如何使用注释来管理获取和设置属性

我想使用注释来映射带有sql列的类属性,然后我编写了这段代码,但是我不知道这是否正确,我想添加一个字典项目,使用注释中使用的名称作为键,但是我不知道以下代码是否是执行此操作的最快方法,例如,有没有一种方法可以在不指定字符串的情况下将该属性放入该属性中? (this.GetType()。GetProperty(“ Id”)

public class Key : Attribute {
            public string Key { get; set; }

            public Key(string key) {
                Key = key;
            }
    }

-

public class Example {

        public IDictionary<string,object> Attributes = new Dictionary<string,object>();

        [Key("id")]
        public Guid Id {
            get { return (Guid) Attributes[((KeyName)this.GetType().GetProperty("Id").getcustomAttributes(typeof(Guid),true).First()).Key]; } 
            set { Attributes.Add(((KeyName)this.GetType().GetProperty("Id").getcustomAttributes(typeof(Guid),true).First()).Key,value); }
        }

}
maxwel112 回答:如何使用注释来管理获取和设置属性

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3130776.html

大家都在问