[CodonNameAttribute("MyCodon")]
public class MyCodonCodon : AbstractCodon
{
[XmlMemberAttributeflagAttribute("testMe", IsRequired=true)]
string testMe = null;
[XmlMemberAttributeflagAttribute("testMeToo")]
string testMeToo = null;
// canonical properties :)
public string TestMe {
get;
set;
}
public string TestMeToo {
get;
set;
}
}以前没有接触过,,,
[CodonNameAttribute] 估计是程序里面自己定义的, 不是 .net 默认提供, [XmlMemberAttributeflagAttribute] 可能是 .net 自带
谁能解释一下, 或者说下这类的用法的详细资料在哪儿能查? thx~
sigh, 我还留守在公司苦苦跟难缠的代码, 文档搏斗...
/// 数据表描述标签
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)] //这句话表示DataTableDesc只能使用到类上
public class DataTableDescAttribute : System.Attribute //必须继承这个基类
{
string _tableName; //数据表名称
string _identity; //自增字段 public DataTableDescAttribute(string tableName)
{
this._tableName = tableName;
} public string TableName
{
get{ return this._tableName; }
}
public string Identity
{
get{ return this._identity; }
set{ this._identity = value;}
}比如你数据库里有个表叫t_user,对应的实体类是User,然后用DataTableDesc来记录书库表信息:
[DataTableDesc("t_user", Identity = "id")]
class User
{
int _id;
string _name;
int_age;
//属性,省略不写了
}
然后你可以在反射里得到User类的DataTableDesc里的信息,这样你就可以动态拼sql语句了
DataTableDescAttribute tableDesc = Attribute.GetCustomAttribute(typeof(User), typeof(DataTableDescAttribute));
tableDesc.TableName,这样你就在运行时拿到了User类对应的表明 t_user注意DataTableDescAttribute推荐以Attribute结尾,这样你就可以[DataTableDesc("t_user", Identity = "id")]使用了
还有Identity = "id" Identity是属性,所以可以选择给不给这个属性赋值
比如你说的这个[XmlMemberAttributeflagAttribute("testMe", IsRequired=true)]
就是
XmlMemberAttributeflagAttribute:Attribute 然后就好像调用它的构造方法一样