Attribute code
[AttributeUsage(AttributeTargets.Property, Inherited = true)]
class IgnoreAttribute : Attribute
{
}
Base class
abstract class ManagementUnit
{
[Ignore]
public abstract byte UnitType { get; }
}
Main class
class Region : ManagementUnit
{
public override byte UnitType
{
get { return 0; }
}
private static void Main()
{
Type t = typeof(Region);
foreach (PropertyInfo p in t.GetProperties())
{
if (p.GetCustomAttributes(typeof(IgnoreAttribute), true).Length != 0)
Console.WriteLine("have attr");
else
Console.WriteLine("don't have attr");
}
}
}
Output: don't have attr
Explain why this is happening? After all, it must inherited.
from http://aclacl.brinkster.net/InsideC/32ch09f.htm
Check the chapter Specifying Inheritance Attribute Rules
EDIT: check Inheritance of Custom Attributes on Abstract Properties
The first answer: