属性控制类
[AttributeUsage(AttributeTargets.Class, Inherited =false)]
[ComVisible(
true)]
publicclass ClassKeyAttribute : Attribute
{
public ClassKeyAttribute()
{

}
public ClassKeyAttribute(string TableName)
{
this.TableName = TableName;
}
publicstring TableName { get; set; }

publicstaticstring GetTableName<T>()
{
T model
= (T)Activator.CreateInstance(typeof(T));
return GetTableName(model);
}

publicstaticstring GetTableName(object model)
{
object[] attributes = model.GetType().GetCustomAttributes(false);
foreach (object o in attributes)
{
if (o is ClassKeyAttribute)
{
ClassKeyAttribute attr
= (ClassKeyAttribute)o;
return attr.TableName;
}
}
return"";
}
}

 

相关文章:

  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-08-16
  • 2021-12-02
  • 2022-01-17
  • 2022-12-23
猜你喜欢
  • 2021-06-02
  • 2021-11-19
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2021-09-06
相关资源
相似解决方案