所有可以定制的特性是什么?

来源:互联网 发布:淘宝店导航css代码 编辑:程序博客网 时间:2024/06/07 05:45

using System;

 

public class MyAttribute : Attribute

{

    public MyAttribute(int i)

    {

    }

}

//[assembly:MyAttribute(1)]

//[module:MyAttribute(2)]

//应用于类型

[type: MyAttribute(3)]

class MyType

{

 

    int _age;

 

    //应用于属性

 

    [property: MyAttribute(4)]

 

    public int Age

    {

 

        get { return _age; }

 

        set { _age = value; }

 

    }

 

    //应用于事件

 

    [event: MyAttribute(5)]

 

    public event EventHandler MyHandler;

 

    //应用于字段上

 

    [field: MyAttribute(6)]

 

    public int fieldMember;

 

    //应用于返回值

 

    [return: MyAttribute(7)]

 

    //应用于方法

 

    [method: MyAttribute(8)]

 

    //应用于方法参数

 

    public Int32 MyMethod([param: MyAttribute(9)]Int32 someParam)

    {

 

        return someParam;

 

    }

 

}

 

原创粉丝点击