为什么我不能从派生类中的 XML 文档注释标记中引用基类中的可访问成员?



>假设我有这个:

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 .

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

没有特别的理由要求这样做。Roslyn 代码库包含一个测试,专门测试找不到基类符号(CrefTests.TypeScope4(,其中提到原因很简单,因为这是以前的编译器所做的:

// As in dev11, we ignore the inherited method symbol.

这看起来像一个历史性的事故,由于解决方法是微不足道的,因此不太可能被改变。

最新更新