【发布时间】:2011-01-31 23:29:46
【问题描述】:
我有一个自定义属性,我想将其应用于我的基本抽象类,以便在以 HTML 显示项目时跳过用户不需要查看的元素。似乎覆盖基类的属性没有继承属性。
覆盖基础属性(抽象或虚拟)是否会破坏原始属性上的属性?
来自属性类定义
[AttributeUsage(AttributeTargets.Property,
Inherited = true,
AllowMultiple = false)]
public class NoHtmlOutput : Attribute
{
}
来自抽象类定义
[NoHtmlOutput]
public abstract Guid UniqueID { get; set; }
来自具体的类定义
public override Guid UniqueID{ get{ return MasterId;} set{MasterId = value;}}
从类检查属性
Type t = o.GetType();
foreach (PropertyInfo pi in t.GetProperties())
{
if (pi.GetCustomAttributes(typeof(NoHtmlOutput), true).Length == 1)
continue;
// processing logic goes here
}
【问题讨论】:
标签: c# reflection attributes abstract-class