2020年9月14日 星期一

the Attribute suffix may be omitted (轉貼)

 C#

using System;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public class SimpleAttribute: Attribute 
{
    ...
}

defines an attribute class named SimpleAttribute that can be placed on class_declarations and interface_declarations only. The example

C#
[Simple] class Class1 {...}

[Simple] interface Interface1 {...}

shows several uses of the Simple attribute. Although this attribute is defined with the name SimpleAttribute, when this attribute is used, the Attribute suffix may be omitted, resulting in the short name Simple. Thus, the example above is semantically equivalent to the following:

C#
[SimpleAttribute] class Class1 {...}

[SimpleAttribute] interface Interface1 {...}

沒有留言:

張貼留言