I have a piece of code like this:
[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
}
what does the attribute return:
mean?
I'd never come across it before, but it seems to be described as attribute targets in 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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With