首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

一个比较奇怪的构造器解决办法

2013-09-27 
一个比较奇怪的构造器 [AttributeUsage(AttributeTargets.Class)]public class PrimaryKeyAttribute : Att

一个比较奇怪的构造器


 [AttributeUsage(AttributeTargets.Class)]
    public class PrimaryKeyAttribute : Attribute
    {
        public PrimaryKeyAttribute(string primaryKey)
        {
            Value = primaryKey;
            autoIncrement = true;
        }

        public string Value { get; private set; }
        public string sequenceName { get; set; }
        public bool autoIncrement { get; set; }
    }
//实例化
 [TableName("tbCSW_HJCGLPlanning")]
    [PrimaryKey("PID", autoIncrement = true)]
    [ExplicitColumns]
    public class tbCSW_HJCGLPlanning : Repo.Record<tbCSW_HJCGLPlanning>  
    {

我没看到有
 [PrimaryKey("PID", autoIncrement = true)]
这个的构造函数,鼠标放上去的时候提示:命名参数。
有点怪,难道可以像js那样动态赋予属性吗? class
[解决办法]
这是Attribute的一种写法而已。
本质上来说,虽然写法不同,编译器却做了相同的处理。

热点排行