I created a custom attribute to decorate several classes that I want to request 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 comes from an abstract base class:
[Example("BaseExample")] public abstract class ExampleContentControl : UserControl {
Do I need to put this attribute on every derived class, even if I add it to the base class? The attribute is marked as inherited, but when I execute the request, I see only the base class, 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
inheritance reflection c # attributes custom-attributes
Wonderko the sane
source share