Hello All,
I have created a custom Attribute to decorate a number of classes that I want to query for at runtime:
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public class ExampleAttribute : Attribute
{
public ExampleAttribute(string name)
{
this.Name = name;
}
public string Name
{
get;
private set;
}
}
Each of these classes derive from an abstract base class:
[Example("BaseExample")]
public abstract class ExampleContentControl : UserControl
{
// class contents here
}
public class DerivedControl : ExampleContentControl
{
// class contents here
}
Do I need to put this attribute on each derived class, even if I add it to the base class? The attribute is marked as inheritable, but when I do the query, I only see the base class and not the derived classes.
From another thread:
var typesWithMyAttribute =
from a in AppDomain.CurrentDomain.GetAssemblies()
from t in a.GetTypes()
let attributes = t.GetCustomAttributes(typeof(ExampleAttribute), true)
where attributes != null && attributes.Length > 0
select new { Type = t, Attributes = attributes.Cast<ExampleAttribute>() };
Thanks, wTs