c# - c#中的属性返回是什么意思?

标签 c#

我有一段代码是这样的:

[return: XmlElement("return", Namespace = "", IsNullable = false, DataType = "base64Binary")]
public byte[] WORK([XmlElement(Namespace = "http://www.example.com/xml/someapi", DataType = "string", Form = XmlSchemaForm.Qualified)] string guid, [XmlElement(Namespace = "http://www.example.com/xml/someapi", DataType = "base64Binary", Form = XmlSchemaForm.Qualified)] byte[] data) {

   // some work
}

属性 return: 是什么意思?

最佳答案

我以前从未遇到过它,但它似乎在 Disabmbiguating Attribute Targets 中被描述为属性目标

This sort of situation arises frequently when marshaling. To resolve the ambiguity, C# has a set of default targets for each kind of declaration, which can be overridden by explicitly specifying attribute targets. C#

// default: applies to method 
[SomeAttr] 
int Method1() { return 0; } 

// applies to method 
[method: SomeAttr] 
int Method2() { return 0; } 

// applies to return value 
[return: SomeAttr] 
int Method3() { return 0; } 

Note that this is independent of the targets on which SomeAttr is defined to be valid; that is, even if SomeAttr were defined to apply only to return values, the return target would still have to be specified. In other words, the compiler will not use AttributeUsage information to resolve ambiguous attribute targets. For more information, see AttributeUsage (C# Programming Guide). The syntax for attribute targets is as follows: [target : attribute-list]

关于c# - c#中的属性返回是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31129718/

相关文章:

c# - 为什么 null 传播不一致地传播 Nullable<T>?

C# HttpClient POST 请求处理响应

c# - 所有参数的 WCF WebInvoke POST null

c# - 如何减少和清除内存泄漏?

c# - 与委托(delegate)一起解释这段代码

C# - 使用非主线程更新 GUI

c# - 如何查找字符串是否包含任何特殊字符?

c# - String.StartsWith 不支持亚洲语言?

c# - 使用图形 API 在 Azure AD B2C 中创建具有自定义属性的用户

c# - .net Webbrowser控件显示不一样