AttributeUsage

C#中, 有的类上面添加了[AttributeUsage(AttributeTargets.Property)]

这个是什么作用呢?

AttributeUsage 枚举类型

成员名称                   说明

All         可以对任何应用程序应用属性

Assembly                 可以对程序集应用属性

Class                        可以对类应用属性

Constructor       可以对构造函数应用属性。  

Delegate       可以对委托应用属性。  

Enum         可以对枚举应用属性。 

Event         可以对事件应用属性。  

Field          可以对字段应用属性。  

GenericParameter   可以对泛型参数应用属性。  

Interface       可以对接口应用属性。  

Method        可以对方法应用属性。  

Module        可以对模块应用属性。 注意 Module 指的是可移植的可执行文件(.dll 或 .exe),而非 Visual Basic 标准模块。

Parameter       可以对参数应用属性。  

Property       可以对属性 (Property) 应用属性 (Attribute)。  

ReturnValue     可以对返回值应用属性。  

Struct         可以对结构应用属性,即值类型 

原文地址:https://www.cnblogs.com/douqiumiao/p/3003684.html