自定義特性。配合列舉使用棒棒噠

2022-02-21 06:15:56 字數 1570 閱讀 2717

1

///2

///自定義特性,比系統的display增加了一些引數 created by zhangqc 2015.08.19

3///

4 [attributeusage(attributetargets.field |attributetargets.property,

5 allowmultiple = false, inherited = false)]6

public

sealed

class

customattribute:attribute710

11public

object value

1213

public

object value1

1415

public

object value2

1617

18///

19///

無參建構函式(enum寫法[custom(name="xx",value=xx1,value1=xx2,value2=xx3)]) created by zhangqc 2015.08.19

20///

21public

customattribute()

2224

25///

26///

有參建構函式(enum寫法[custom("xx",xx1,xx2,xx3)]) created by zhangqc 2015.08.19

27///

28///

29///

30///

31///

32public customattribute(string name,object value,object value1,object

value2)

3339

40///

41///

有參建構函式(enum寫法[custom("xx")]) created by zhangqc 2015.08.19

42///

43///

44public customattribute(string

name)

4548

49///

50///

有參建構函式(enum寫法[custom("xx",xx1)]) created by zhangqc 2015.08.19

51///

52///

53///

54public customattribute(string name, object

value)

5559

///60

///有參建構函式(enum寫法[custom("xx",xx1,xx2)]) created by zhangqc 2015.08.19

61///

62///

63///

64///

65public customattribute(string name, object value, object

value1)

6670

71 }

自定義列舉特性

新增乙個列舉擴充套件類 列舉擴充套件特性 attributeusage attributetargets.field attributetargets.enum public class apienum attribute set public string message set 列舉特性 訊息碼...

自定義列舉

在效能優化中,列舉的每乙個都是乙個例項,比較耗記憶體,採用自定義註解能很好的解決這個問題 public class shape 表示表示需要在什麼級別儲存該注釋資訊,用於描述註解的生命週期 retention retentionpolicy.runtime public inte ce model ...

自定義特性

1.指定attributeusage特性 特性 attribute 類本身用乙個特性 system.attributeusage特性來標記。attributeusage主要用於標識自定義特性可以應用到哪些型別的程式元素上。這些資訊由它的第一引數給出,改引數是必選的,其型別是列舉型別的attribut...