首页 > 代码库 > 自定义特性。配合枚举使用棒棒哒
自定义特性。配合枚举使用棒棒哒
1 /// <summary> 2 /// 自定义特性,比系统的display增加了一些参数 Created by ZhangQC 2015.08.19 3 /// </summary> 4 [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, 5 AllowMultiple = false, Inherited = false)] 6 public sealed class CustomAttribute:Attribute 7 { 8 9 public string Name { get; set; } 10 11 public object Value { get; set; } 12 13 public object Value1 { get; set; } 14 15 public object Value2 { get; set; } 16 17 18 /// <summary> 19 /// 无参构造函数(Enum写法[Custom(Name="xx",Value=http://www.mamicode.com/xx1,Value1=xx2,Value2=xx3)]) Created by ZhangQC 2015.08.19>20 /// </summary> 21 public CustomAttribute() 22 { 23 } 24 25 /// <summary> 26 /// 有参构造函数(Enum写法[Custom("xx",xx1,xx2,xx3)]) Created by ZhangQC 2015.08.19 27 /// </summary> 28 /// <param name="name"></param> 29 /// <param name="value"></param> 30 /// <param name="value1"></param> 31 /// <param name="value2"></param> 32 public CustomAttribute(string name,object value,object value1,object value2) 33 { 34 this.Name = name; 35 this.Value =http://www.mamicode.com/ value; 36 this.Value1 = value1; 37 this.Value2 = value2; 38 } 39 40 /// <summary> 41 /// 有参构造函数(Enum写法[Custom("xx")]) Created by ZhangQC 2015.08.19 42 /// </summary> 43 /// <param name="name"></param> 44 public CustomAttribute(string name) 45 { 46 this.Name = name; 47 } 48 49 /// <summary> 50 /// 有参构造函数(Enum写法[Custom("xx",xx1)]) Created by ZhangQC 2015.08.19 51 /// </summary> 52 /// <param name="name"></param> 53 /// <param name="value"></param> 54 public CustomAttribute(string name, object value) 55 { 56 this.Name = name; 57 this.Value =http://www.mamicode.com/ value; 58 } 59 /// <summary> 60 /// 有参构造函数(Enum写法[Custom("xx",xx1,xx2)]) Created by ZhangQC 2015.08.19 61 /// </summary> 62 /// <param name="name"></param> 63 /// <param name="value"></param> 64 /// <param name="value1"></param> 65 public CustomAttribute(string name, object value, object value1) 66 { 67 this.Name = name; 68 this.Value =http://www.mamicode.com/ value; 69 } 70 71 }
自定义特性。配合枚举使用棒棒哒
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。