lundi 24 août 2015

C# Method Attributes

Is there a way to achieve this without injection? Topic is a UserControl. I am trying to check for Title and set it in Attribute.

public partial class Topic: TopicBase
{
[Topic(Title = "My Topic")]
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
}

When I look for the Attribute I get null in TopicBase.cs

protected override void OnInit(EventArgs e)
    {
        var topicAttr = Attribute.GetCustomAttribute(this.GetType(), typeof(TopicAttribute)); //topicAttr is null here.
        if (topicAttr != null)
        {
            SetTopic(((TopicAttribute)topicAttr).Title);
        }
    }





Aucun commentaire:

Enregistrer un commentaire