Is there a way to access PrepertyInfo from attribute assigned to a propery
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.
精彩评论