123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Reflection;
- namespace CommonLang.Property
- {
- /// <summary>
- /// 编辑器支持,描述性文件
- /// </summary>
- [AttributeUsage(AttributeTargets.All)]
- public class DescAttribute : System.Attribute
- {
- readonly string desc;
- readonly string category;
- readonly bool editable;
- readonly string detail;
- public DescAttribute(string desc)
- : this(desc, "", true, null)
- {
- }
- public DescAttribute(string desc, string category)
- : this(desc, category, true, null)
- {
- }
- public DescAttribute(string desc, string category, bool editable)
- : this(desc, category, editable, null)
- {
- }
- public DescAttribute(string desc, string category, bool editable, string detail)
- {
- this.desc = desc;
- this.category = category;
- this.editable = editable;
- this.detail = detail;
- }
- public string Desc
- {
- get { return desc; }
- }
- public string Category
- {
- get { return category; }
- }
- public bool Editable
- {
- get { return editable; }
- }
- public string Detail
- {
- get { return detail; }
- }
- }
- /// <summary>
- /// 某个字段依赖于某个开关(字段或者属性)
- /// </summary>
- [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
- public class DependOnPropertyAttribute : System.Attribute
- {
- readonly string property_name;
- readonly bool expect;
- public DependOnPropertyAttribute(string property_name, bool expect = true)
- {
- this.property_name = property_name;
- this.expect = expect;
- }
- public string PropertyName { get { return property_name; } }
- public bool Expect { get { return expect; } }
- }
- /// <summary>
- /// 某个字段依赖于某个开关(字段或者属性)
- /// </summary>
- [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
- public class DependOnPropertyExtAttribute : System.Attribute
- {
- readonly string property_name;
- readonly int expect;
- public DependOnPropertyExtAttribute(string property_name, int expect = 0)
- {
- this.property_name = property_name;
- this.expect = expect;
- }
- public string PropertyName { get { return property_name; } }
- public int Expect { get { return expect; } }
- }
- /// <summary>
- /// 编辑器支持,描述列表的成员类型
- /// </summary>
- [AttributeUsage(AttributeTargets.Field)]
- public class ListAttribute : System.Attribute
- {
- private List<Type> elementTypes;
- public ListAttribute(params Type[] types)
- {
- HashMap<Type, Type> typeSet = new HashMap<Type, Type>();
- foreach (Type type in types)
- {
- if (type.IsAbstract)
- {
- foreach (Type sub in ReflectionUtil.GetNoneVirtualSubTypes(type))
- {
- typeSet.Add(sub, sub);
- }
- }
- else
- {
- typeSet.Add(type, type);
- }
- }
- this.elementTypes = new List<Type>(typeSet.Keys);
- }
- public List<Type> ElementTypes
- {
- get { return elementTypes; }
- }
- }
- /// <summary>
- /// 编辑器支持,描述一个类的主键是什么
- /// </summary>
- [AttributeUsage(AttributeTargets.Class)]
- public class TableClassAttribute : System.Attribute
- {
- private string id_field;
- public TableClassAttribute(string key)
- {
- this.id_field = key;
- }
- public string PrimaryKey
- {
- get { return id_field; }
- }
- }
- /// <summary>
- /// 编辑器支持,此类型是可折叠
- /// </summary>
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Property)]
- public class ExpandableAttribute : System.Attribute
- {
- }
- /// <summary>
- /// 编辑器支持,字段是否可删除或改变
- /// </summary>
- [AttributeUsage(AttributeTargets.Field)]
- public class NotNullAttribute : System.Attribute
- {
- }
- /// <summary>
- /// 列取当前字段可能的值
- /// </summary>
- [AttributeUsage(AttributeTargets.Field)]
- public class OptionalValueAttribute : System.Attribute
- {
- public string[] Values { get; private set; }
- public OptionalValueAttribute(params string[] args)
- {
- this.Values = args;
- }
- }
- //----------------------------------------------------------------------------
- #region Type
- /// <summary>
- /// 标识 Field 字段为颜色
- /// </summary>
- [AttributeUsage(AttributeTargets.Field)]
- public class Int32ColorAttribute : System.Attribute
- {
- }
- /// <summary>
- /// 标识 Field 字段为文件
- /// </summary>
- [AttributeUsage(AttributeTargets.Field)]
- public class FilePathAttribute : System.Attribute
- {
- }
- /// <summary>
- /// 标识 Field 字段为目录
- /// </summary>
- [AttributeUsage(AttributeTargets.Field)]
- public class DirectoryPathAttribute : System.Attribute
- {
- }
- #endregion
- }
|