[AttributeUsage(AttributeTargets.Field)]
public class UColumn : Attribute
{
public DBField type; public UColumn(DBField type)
{
this.type = type;
}
}
[AttributeUsage(AttributeTargets.Class)]
public class UTable : Attribute
{
public string tableName;
public UTable(string tableName)
{
tableName = tableName ?? throw new ArgumentNullException(nameof(tableName));
} }
先定义了俩attribute,一个作用在类上,一个作用在字段上,然后
[UTable("T_Content")]
public class T_Content
{
[UColumn(DBField.None)]
private string contentID;
private string content_AlarmID;
private string message;
private string user;
private DateTime? dateTime = null;
public string ContentID { get => contentID; set => contentID = value; }
public string Content_AlarmID { get => content_AlarmID; set => content_AlarmID = value; }
public string Message { get => message; set => message = value; }
public string User { get => user; set => user = value; }
public DateTime? DateTime { get => dateTime; set => dateTime = value; }
}
实体类上加attribute
然后测试 发现可以获取到UTable但是获取不到UColumn
然后是测试代码:
public class UColumn : Attribute
{
public DBField type; public UColumn(DBField type)
{
this.type = type;
}
}
[AttributeUsage(AttributeTargets.Class)]
public class UTable : Attribute
{
public string tableName;
public UTable(string tableName)
{
tableName = tableName ?? throw new ArgumentNullException(nameof(tableName));
} }
先定义了俩attribute,一个作用在类上,一个作用在字段上,然后
[UTable("T_Content")]
public class T_Content
{
[UColumn(DBField.None)]
private string contentID;
private string content_AlarmID;
private string message;
private string user;
private DateTime? dateTime = null;
public string ContentID { get => contentID; set => contentID = value; }
public string Content_AlarmID { get => content_AlarmID; set => content_AlarmID = value; }
public string Message { get => message; set => message = value; }
public string User { get => user; set => user = value; }
public DateTime? DateTime { get => dateTime; set => dateTime = value; }
}
实体类上加attribute
然后测试 发现可以获取到UTable但是获取不到UColumn
然后是测试代码:
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货