简体   繁体   English

向使用反射创建的类型添加自定义属性

[英]Adding a custom attribute to a type created using reflection

I have created a type and with few properties and assigned values to those properties.我已经创建了一个类型和几个属性,并为这些属性分配了值。 I need to bind this class with a property grid.我需要将此 class 与属性网格绑定。 I need to add/decorate custom attribute to some of the properties i have created using reflection.我需要为我使用反射创建的一些属性添加/装饰自定义属性。

Could some one help me adding a custom attribute using reflection.有人可以帮助我使用反射添加自定义属性吗?

[TypeConverter(typeof(DropDownConverter))]
        public string NAME
        {
            get { return m_name; }
            set
            {
                m_name = value;
            }
        }

Finally the property should have a TypeConverter attribute added to it.最后,该属性应该添加一个 TypeConverter 属性。

Thanks, Kishore Borra.谢谢,基肖博拉。

You need to implement ICustomTypeDescriptor and implement GetProperties to return custom PropertyDescriptor s that contain you attributes.您需要实现ICustomTypeDescriptor并实现GetProperties以返回包含您属性的自定义PropertyDescriptor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM