属性控制类
[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"";
}
}
[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"";
}
}