[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public class ColumAttribute : Attribute
{
private string _columName;
private DbType _dbType;
public ColumAttribute() { }
public ColumAttribute(string columName) : this() { _columName = columName; }
public ColumAttribute(string columName, DbType dbType) : this(columName) { _dbType = dbType; }
public virtual string ColumName
{
get { return _columName; }
set { _columName = value; }
}
public DbType DbType
{
get { return _dbType; }
set { _dbType = value; }
}
}
ColumAttribute() → (string) → (string, DbType),避免程式碼重複。ColumName 設為 virtual,允許衍生特性覆寫。DbType 屬性對應 System.Data.DbType 列舉,支援精確型別映射。AttributeUsage 限制只能套用於屬性(AttributeTargets.Property)。此特性配合 TableAttribute,構成簡易 ORM 映射的特性基礎設施。