Inheritance of Custom Attributes on Abstract Properties
Posted
by Marty Trenouth
on Stack Overflow
See other posts from Stack Overflow
or by Marty Trenouth
Published on 2010-03-25T23:00:04Z
Indexed on
2010/03/25
23:03 UTC
Read the original article
Hit count: 427
I've got a custom attribute that I want to apply to my base abstract class so that I can skip elements that don't need to be viewed by the user when displaying the item in HTML. It seems that the properties overriding the base class are not inheriting the attributes.
Does overriding base properties (abstract or virtual) blow away attributes placed on the original property?
From Attribute class Defination
[AttributeUsage(AttributeTargets.Property,
Inherited = true,
AllowMultiple = false)]
public class NoHtmlOutput : Attribute
{
}
From Abstract Class Defination
[NoHtmlOutput]
public abstract Guid UniqueID { get; set; }
From Concrete Class Defination
public override Guid UniqueID{ get{ return MasterId;} set{MasterId = value;}}
From class checking for attribute
Type t = o.GetType();
foreach (PropertyInfo pi in t.GetProperties())
{
if (pi.GetCustomAttributes(typeof(NoHtmlOutput), true).Length == 1)
continue;
// processing logic goes here
}
© Stack Overflow or respective owner