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
Post a Comment