C#之特性

自定义自己的特性方法 MyCustom

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
    public sealed class MyCustomAttribute : Attribute
    {
        public MyCustomAttribute() 
        { 
        
        }

        public MyCustomAttribute(string name)
        { 
        
        }
    }

关于 MyCustom 使用

    [Serializable()]
    public class AttributeExam
    {

        [MyCustom()]
        public int Index;

        [MyCustom()]
        public string Name;

        [MyCustom("name")]
        public void Run()
        {

        }

        [MyCustom("name")]
        public string Say()
        {
            return "MyCustom";
        }
    }

 

posted @ 2023-07-09 16:48  EhuanRum  阅读(14)  评论(0)    收藏  举报