c# - Is there a way to get the declaring method/property of an Attribute at runtime -
this question has answer here:
- how member custom attribute applied? 4 answers
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
Post a Comment