Attributes.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Reflection;
  5. namespace CommonLang.Property
  6. {
  7. /// <summary>
  8. /// 编辑器支持,描述性文件
  9. /// </summary>
  10. [AttributeUsage(AttributeTargets.All)]
  11. public class DescAttribute : System.Attribute
  12. {
  13. readonly string desc;
  14. readonly string category;
  15. readonly bool editable;
  16. readonly string detail;
  17. public DescAttribute(string desc)
  18. : this(desc, "", true, null)
  19. {
  20. }
  21. public DescAttribute(string desc, string category)
  22. : this(desc, category, true, null)
  23. {
  24. }
  25. public DescAttribute(string desc, string category, bool editable)
  26. : this(desc, category, editable, null)
  27. {
  28. }
  29. public DescAttribute(string desc, string category, bool editable, string detail)
  30. {
  31. this.desc = desc;
  32. this.category = category;
  33. this.editable = editable;
  34. this.detail = detail;
  35. }
  36. public string Desc
  37. {
  38. get { return desc; }
  39. }
  40. public string Category
  41. {
  42. get { return category; }
  43. }
  44. public bool Editable
  45. {
  46. get { return editable; }
  47. }
  48. public string Detail
  49. {
  50. get { return detail; }
  51. }
  52. }
  53. /// <summary>
  54. /// 某个字段依赖于某个开关(字段或者属性)
  55. /// </summary>
  56. [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
  57. public class DependOnPropertyAttribute : System.Attribute
  58. {
  59. readonly string property_name;
  60. readonly bool expect;
  61. public DependOnPropertyAttribute(string property_name, bool expect = true)
  62. {
  63. this.property_name = property_name;
  64. this.expect = expect;
  65. }
  66. public string PropertyName { get { return property_name; } }
  67. public bool Expect { get { return expect; } }
  68. }
  69. /// <summary>
  70. /// 某个字段依赖于某个开关(字段或者属性)
  71. /// </summary>
  72. [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
  73. public class DependOnPropertyExtAttribute : System.Attribute
  74. {
  75. readonly string property_name;
  76. readonly int expect;
  77. public DependOnPropertyExtAttribute(string property_name, int expect = 0)
  78. {
  79. this.property_name = property_name;
  80. this.expect = expect;
  81. }
  82. public string PropertyName { get { return property_name; } }
  83. public int Expect { get { return expect; } }
  84. }
  85. /// <summary>
  86. /// 编辑器支持,描述列表的成员类型
  87. /// </summary>
  88. [AttributeUsage(AttributeTargets.Field)]
  89. public class ListAttribute : System.Attribute
  90. {
  91. private List<Type> elementTypes;
  92. public ListAttribute(params Type[] types)
  93. {
  94. HashMap<Type, Type> typeSet = new HashMap<Type, Type>();
  95. foreach (Type type in types)
  96. {
  97. if (type.IsAbstract)
  98. {
  99. foreach (Type sub in ReflectionUtil.GetNoneVirtualSubTypes(type))
  100. {
  101. typeSet.Add(sub, sub);
  102. }
  103. }
  104. else
  105. {
  106. typeSet.Add(type, type);
  107. }
  108. }
  109. this.elementTypes = new List<Type>(typeSet.Keys);
  110. }
  111. public List<Type> ElementTypes
  112. {
  113. get { return elementTypes; }
  114. }
  115. }
  116. /// <summary>
  117. /// 编辑器支持,描述一个类的主键是什么
  118. /// </summary>
  119. [AttributeUsage(AttributeTargets.Class)]
  120. public class TableClassAttribute : System.Attribute
  121. {
  122. private string id_field;
  123. public TableClassAttribute(string key)
  124. {
  125. this.id_field = key;
  126. }
  127. public string PrimaryKey
  128. {
  129. get { return id_field; }
  130. }
  131. }
  132. /// <summary>
  133. /// 编辑器支持,此类型是可折叠
  134. /// </summary>
  135. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Property)]
  136. public class ExpandableAttribute : System.Attribute
  137. {
  138. }
  139. /// <summary>
  140. /// 编辑器支持,字段是否可删除或改变
  141. /// </summary>
  142. [AttributeUsage(AttributeTargets.Field)]
  143. public class NotNullAttribute : System.Attribute
  144. {
  145. }
  146. /// <summary>
  147. /// 列取当前字段可能的值
  148. /// </summary>
  149. [AttributeUsage(AttributeTargets.Field)]
  150. public class OptionalValueAttribute : System.Attribute
  151. {
  152. public string[] Values { get; private set; }
  153. public OptionalValueAttribute(params string[] args)
  154. {
  155. this.Values = args;
  156. }
  157. }
  158. //----------------------------------------------------------------------------
  159. #region Type
  160. /// <summary>
  161. /// 标识 Field 字段为颜色
  162. /// </summary>
  163. [AttributeUsage(AttributeTargets.Field)]
  164. public class Int32ColorAttribute : System.Attribute
  165. {
  166. }
  167. /// <summary>
  168. /// 标识 Field 字段为文件
  169. /// </summary>
  170. [AttributeUsage(AttributeTargets.Field)]
  171. public class FilePathAttribute : System.Attribute
  172. {
  173. }
  174. /// <summary>
  175. /// 标识 Field 字段为目录
  176. /// </summary>
  177. [AttributeUsage(AttributeTargets.Field)]
  178. public class DirectoryPathAttribute : System.Attribute
  179. {
  180. }
  181. #endregion
  182. }