Assuming I have the following hierarchy:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class GrandpaAttribute : Attribute
{
public GrandpaAttribute() {}
}
public class ParentAttribute() : GrandpaAttribute
{
public string Name { get; }
public ParentAttribute(string name)
{
Name = name;
}
}
public class ChildAttribute() : ParentAttribute
{
public int Number { get; }
public ChildAttribute(string name, int number) : base(name)
{
Number = number;
}
}
In a given application, I use the ChildAttribute
attribute:
public class Foo
{
[Child("The Beast", 666)]
public string Description { get; set; }
public DateTime SomeDate { get; set; }
}
Doubt has arisen:
Is it possible to abstract the inheritance to understand that the Description
property has the GrandpaAttribute
attribute?
My intention is to get an instance of GrandaAttribute
defined in a property of class Foo
as ParentAttribute
, ChildAttribute
or any other attribute derived from it.