【问题标题】:Change xml description of property in derived class更改派生类中属性的 xml 描述
【发布时间】:2019-03-28 15:09:54
【问题描述】:

有没有办法在不重写 getter 和 setter 声明的情况下更改派生类中属性的 xml 描述? 例子:

public abstract class BaseClass
{
    /// <summary>
    /// description of foo in BaseClass
    /// </summary>
    public int foo
    {
        get { /* do something */ }
        set { /* do something */ }
    }
}

public sealed class DerivedClass: BaseClass
{
    /// <summary>
    /// description of foo in DerivedClass
    /// </summary>
    public int foo
    {
        get { /* do something */ }
        set { /* do something */ }
    }
}

foo 的实现在两个类中应该相同,只是描述发生了变化。

【问题讨论】:

    标签: c# inheritance properties xml-comments


    【解决方案1】:

    不,基本上。不过,您不需要添加新的实现 - 您可以使用:

    /// <summary>
    /// description of foo in DerivedClass
    /// </summary>
    public int foo
    {
        get { return base.foo; }
        set { base.foo = value = value; }
    }
    

    但是您需要重新声明该方法。这可以通过virtual / override 对,也可以通过new(成员隐藏)成员。

    【讨论】:

    • 谢谢,我就是这样做的,不知道有没有更紧凑的方式。
    猜你喜欢
    • 1970-01-01
    • 2015-09-18
    • 2018-03-21
    • 2014-08-19
    • 2019-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多