.net中属性Attribute

来源:互联网 发布:linux 获取网卡状态 编辑:程序博客网 时间:2024/05/19 12:11

    .  net中的属性attribute,有的地方也叫特性了,通常是用来修饰类,当然还可以修接口、方法、字段。

加了attribute属性的地方,可以通常过反射的方式来取得特性值。从而进行一些过滤操作。

   用户可以通过继承System.Attribute类来实现自定义的属性。在使用的地方使用反射机制来使用。

   以下是一些用例代码:

  
下面是调用的示例:

    

    结果:

        Method DogMethod has a pet Dog attribute.
        Type is Tom.Test.AnimalTypeAttribute
       Method CatMethod has a pet Cat attribute.
       Type is Tom.Test.AnimalTypeAttribute
       Method BirdMethod has a pet Bird attribute.
       Type is Tom.Test.AnimalTypeAttribute

原创粉丝点击