What means the attribute return in c#?

后端 未结 1 624
谎友^
谎友^ 2021-01-12 09:22

I have a piece of code like this:

[return: XmlElement(\"return\", Namespace = \"\", IsNullable = false, DataType = \"base64Binary\")]
public byte[] WORK([Xml         


        
相关标签:
1条回答
  • 2021-01-12 09:55

    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]

    0 讨论(0)
提交回复
热议问题