zoukankan      html  css  js  c++  java
  • 数据库特性

    /// <summary>
    /// 数据库表名
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class DBTableNameAttribute : Attribute
    {

    public string Name { get; set; }
    public DBTableNameAttribute(string Name)
    {
    this.Name = Name;
    }
    }
    /// <summary>
    /// 主键名
    /// </summary>
    [AttributeUsage(AttributeTargets.Class )]
    public class DBTableFiledPrimaryKeyAttribute : Attribute
    {

    public string Name { get; set; }
    public DBTableFiledPrimaryKeyAttribute(string Name)
    {
    this.Name = Name;
    }
    }
    /// <summary>
    /// 字段名
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class DBTableFiledNameAttribute : Attribute
    {

    public string Name { get; set; }
    public DBTableFiledNameAttribute(string Name)
    {
    this.Name = Name;
    }
    }
    /// <summary>
    /// 唯一值
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class DBTableFiledUniqueAttribute : Attribute
    {


    public DBTableFiledUniqueAttribute( )
    {

    }
    }

    /// <summary>
    /// 对MemberInfo类扩展方法
    /// </summary>
    public static class CustomMemberInfo
    {
    /// <summary>
    /// 判断是否存在相应的特性
    /// </summary>
    /// <typeparam name="T">特性类</typeparam>
    /// <param name="type"></param>
    /// <returns></returns>
    static public bool HasAttribute<T>(this System.Reflection.MemberInfo type) where T : class
    {
    object[] attributes = type.GetCustomAttributes(false);

    foreach (Attribute attr in attributes)
    {

    //判断Attribute 中是否 为 UniqueColumnAttribute

    if (attr is T)
    {
    return true;

    }

    }
    return false;
    }
    /// <summary>
    /// 获取相应的Attribute对象 如 var attr=typeof(Person).GetAttribute<DBTableNameAttribute>();
    /// </summary>
    /// <typeparam name="T">Attribute类</typeparam>
    /// <param name="type">实体类</param>
    /// <returns>Attribute对象</returns>
    static public T GetAttribute<T>(this System.Reflection.MemberInfo type) where T : class
    {


    Attribute classAttribute = Attribute.GetCustomAttribute(type, typeof(T));

    return classAttribute as T;
    }
    }

  • 相关阅读:
    DFC-3C和DFC-3B的区别和注意事项
    Bug搬运工-CSCux99539:Intermittent error message "Power supply 2 failed or shutdown"
    EVE上传Dynamips、IOL和QEMU镜像
    EVE扩大虚拟内存
    EVE磁盘扩容
    VMware安装EVE
    介绍Mobility Group
    Bug搬运工-CSCvi02106 :Cisco 2800, 3800, 1560 APs: when connected to a Cisco Switch CDP-4-DUPLEX_MISMATCH log is seen
    jquery.autocomplete在火狐下的BUG解决
    nodeJS中exports和mopdule.exports的区别
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/5428822.html
Copyright © 2011-2022 走看看