为什么我无法在派生类的XML文档注释标签中引用基类中可访问成员?

3

假设我有这样一个代码:

internal abstract class Animal
{
    internal bool IsExtinct { get; set; }
}

internal sealed class WoollyMammoth : Animal
{
    internal int WeightLbs { get; set; }

    /// <summary>
    /// Construct a new instance with <see cref="IsExtinct"/> // this throws an error "XML comment has cref attribute 'IsExtinct' that could not be resolved".
    /// set to "true" and <see cref="WeightLbs"/> // this works just fine.
    /// initialized to 0.
    /// </summary>
    WoollyMammoth()
    {
        // no problem with either of these, of course.
        IsExtinct = true; 
        WeightLbs = 0;
    }
}

当我尝试从<see/> XML注释标签中引用基类中定义的IsExtinct属性时,为什么会出现错误?我可以访问派生类中定义的属性,如WeightLbs


这个属性可能是私有的吗? - Saša Ćetković
1个回答

8

要引用一个基类符号,请使用限定名称:<see cref="Animal.IsExtinct"/>

这并没有特别的原因需要这样做。Roslyn 代码库包含一个专门测试基类符号未被找到的测试CrefTests.TypeScope4,其中提到的原因仅仅是因为先前的编译器就是这么做的:

// 与 Dev11 一样,我们忽略继承的方法符号。

看起来这是一个历史意外事件,而且由于解决方法很简单,所以不太可能被更改。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接