c# - Access to the value of a Custom Attribute -


ive got custom attribute:

[attributeusage(attributetargets.method, allowmultiple=false, inherited = true)] class methodtestingattibute : attribute {        public string value{ get; private set; }     public methodtestingattibute (string value)     {         this.value= value;      } } 

to used this:

    [methodtestingattibute("2")]     public int m1() {return 3; } 

and dificulty take value of "2" of methodtestingattibute

object result = method.invoke(obj, new type[] {}); // here return 

now want compare result value of method testingattibute. how can that? im trying go road without success: method.getcustomattributes(typeof(methodtestattibute), true)[0]...

what access field of custoum attribute?

var attribute =    (methodtestingattibute)    typeof (vehicles)       .getmethod("m1")       .getcustomattributes(typeof (methodtestingattibute), false).first(); console.writeline(attribute.value); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -