开发者

Is there a way to access PrepertyInfo from attribute assigned to a propery

开发者 https://www.devze.com 2022-12-23 14:30 出处:网络
I have a custom attribute and I need to have the name 开发者_如何转开发of the property that it is on.Write now the name is just a string parameter in the attribute constructor.It works, but just doesn

I have a custom attribute and I need to have the name 开发者_如何转开发of the property that it is on. Write now the name is just a string parameter in the attribute constructor. It works, but just doesn't feel write.

Current Implementation

[ListViewColumnDescription("Key", 1, "My Key", true)]
public Guid Key
{
    get;
    set;
}

Would like something more like this

[ListViewColumnDescription(1, "My Key", true)]
public Guid Key
{
    get;
    set;
}

Edit: I'm actually storing the attributes and using them to look up the properties. It makes it easier to add the properties to the ListViewItem in the correct order. That is what the first parameter is. It is the column number.

Edit 2: I am just setting the property name in the attribute was I find them while looking through the properties.


How are you reading your custom attributes information? You can get and attribute only from PropertyInfo it set assigned to and PropertyInfo has the name of the property you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号