using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace CommonLang.Property
{
///
/// 编辑器支持,描述性文件
///
[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; }
}
}
///
/// 某个字段依赖于某个开关(字段或者属性)
///
[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; } }
}
///
/// 某个字段依赖于某个开关(字段或者属性)
///
[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; } }
}
///
/// 编辑器支持,描述列表的成员类型
///
[AttributeUsage(AttributeTargets.Field)]
public class ListAttribute : System.Attribute
{
private List elementTypes;
public ListAttribute(params Type[] types)
{
HashMap typeSet = new HashMap();
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(typeSet.Keys);
}
public List ElementTypes
{
get { return elementTypes; }
}
}
///
/// 编辑器支持,描述一个类的主键是什么
///
[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; }
}
}
///
/// 编辑器支持,此类型是可折叠
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Property)]
public class ExpandableAttribute : System.Attribute
{
}
///
/// 编辑器支持,字段是否可删除或改变
///
[AttributeUsage(AttributeTargets.Field)]
public class NotNullAttribute : System.Attribute
{
}
///
/// 列取当前字段可能的值
///
[AttributeUsage(AttributeTargets.Field)]
public class OptionalValueAttribute : System.Attribute
{
public string[] Values { get; private set; }
public OptionalValueAttribute(params string[] args)
{
this.Values = args;
}
}
//----------------------------------------------------------------------------
#region Type
///
/// 标识 Field 字段为颜色
///
[AttributeUsage(AttributeTargets.Field)]
public class Int32ColorAttribute : System.Attribute
{
}
///
/// 标识 Field 字段为文件
///
[AttributeUsage(AttributeTargets.Field)]
public class FilePathAttribute : System.Attribute
{
}
///
/// 标识 Field 字段为目录
///
[AttributeUsage(AttributeTargets.Field)]
public class DirectoryPathAttribute : System.Attribute
{
}
#endregion
}