reflection - C# Method Attributes -


is there way achieve without injection? topic usercontrol. trying check title , set in attribute.

public partial class topic: topicbase { [topic(title = "my topic")] protected override void oninit(eventargs e) { base.oninit(e); } } 

when attribute null in topicbase.cs

protected override void oninit(eventargs e)     {         var topicattr = attribute.getcustomattribute(this.gettype(), typeof(topicattribute)); //topicattr null here.         if (topicattr != null)         {             settopic(((topicattribute)topicattr).title);         }     } 

you checking attribute on type. attribute sits on method. either change query or put attribute on type expected query:

[topic(title = "my topic")] public partial class topic : topicbase { } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -