相关疑难解决方法(0)

自定义属性在抽象属性上的继承

我有一个自定义属性,我想应用于我的基本抽象类,以便我可以跳过在HTML中显示项目时用户不需要查看的元素.似乎覆盖基类的属性不继承属性.

重写基本属性(抽象或虚拟)是否会破坏原始属性上的属性?

从属性类定义

[AttributeUsage(AttributeTargets.Property,
                Inherited = true,
                AllowMultiple = false)]
public class NoHtmlOutput : Attribute
{
}
Run Code Online (Sandbox Code Playgroud)

从抽象类定义

[NoHtmlOutput]
public abstract Guid UniqueID { get; set; }
Run Code Online (Sandbox Code Playgroud)

从混凝土类定义

public override Guid UniqueID{ get{ return MasterId;} set{MasterId = value;}}
Run Code Online (Sandbox Code Playgroud)

从类检查属性

        Type t = o.GetType();
        foreach (PropertyInfo pi in t.GetProperties())
        {
            if (pi.GetCustomAttributes(typeof(NoHtmlOutput), true).Length == 1)
                continue;
            // processing logic goes here
        }
Run Code Online (Sandbox Code Playgroud)

c# reflection attributes abstract-class

45
推荐指数
2
解决办法
2万
查看次数

标签 统计

abstract-class ×1

attributes ×1

c# ×1

reflection ×1