gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:38:53 27 4
gpt4 key购买 nike

我有一段代码是这样的:

[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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com