c# - Is there a way to get the declaring method/property of an Attribute at runtime -


this question has answer here:

ok, consider following scenario:

public class foo() {     [fooproperty]     public int blah { { .... } }      ... }  [attributeusage(attributetargets.property)] public class foopropertyattribute: attribute {     public foopropertyattribute()     {         //is there way @ runtime propertyinfo of declaring property 'foo.blah'?     }      ... } 

i know not idea recently, while prototyping classe, question came , i'm curious know if possible.

since actively have hunt these attributes can whatever want.

for instance, if have code this:

foreach (var propertyinfo in type.getproperties()) {     if (propertyinfo.isdefined(typeof(foopropertyattribute), true))     {         var attr = (foopropertyattribute)propertyinfo.getcustomattributes(typeof(foopropertyattribute), true)[0];         attr.foomethod(propertyinfo); // <-- here     } } 

then can see, can pass in property info object it.

other this, no, not built-in attribute system of .net.

there may support in things postsharp hold of different question.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -