I have a piece of code like this:
[return: XmlElement(\"return\", Namespace = \"\", IsNullable = false, DataType = \"base64Binary\")]
public byte[] WORK([Xml
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]