首页 > 代码库 > 自定义特性。配合枚举使用棒棒哒

自定义特性。配合枚举使用棒棒哒

 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 }

 

自定义特性。配合枚举使用棒棒哒