简体   繁体   English

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

[英]Why can't I reference the accessible members in a base class from within XML documentation comment tags in a derived class?

Say I have this: 说我有这个:

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;
    }
}

Why am I getting an error when trying to reference the IsExtinct property, defined in the base class, from the <see/> XML comment tag? 尝试从<see/> XML注释标记引用基类中定义的IsExtinct属性时,为什么会出现错误? I can access properties that are defined in the derived class, like WeightLbs . 我可以访问派生类中定义的属性,例如WeightLbs

To reference a base class symbol, use a qualified name: <see cref="Animal.IsExtinct"/> . 要引用基类符号,请使用限定名称: <see cref="Animal.IsExtinct"/>

There is no particular reason why this should be required. 没有特殊原因为什么需要这样做。 The Roslyn code base contains a test which specifically tests that base class symbols are not found ( CrefTests.TypeScope4 ) which mentions that the reason is simply is because that is what the previous compiler did: Roslyn代码库包含一个测试,该测试专门测试未找到基类符号的情况CrefTests.TypeScope4 ,其中提到的原因仅仅是因为这是先前编译器所做的:

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

It looks like a historic accident, and since the workaround is trivial it's unlikely to be changed. 这看起来像是历史性的事故,而且由于解决方法很简单,因此不太可能更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我不能将基类引用转换为派生类实现的变量接口? - Why can't I cast base reference to a variant interface implemented by derived class? 为什么我不能将一个隐式运算符从Base类写入C#中的Derived类? - Why can't I write an implicit operator from a Base class to a Derived class in C#? 为什么在基类引用中存储派生类型是合法的? - Why is it legal to store a derived type within a base class reference? c#xml注释,cref不能引用基类中定义的方法 - c# xml comment, cref can't reference method defined in base class 为什么派生类无法从基类访问受保护的getter? - Why a derived class can't access a protected getter from the base class? 为什么派生类不能用从原始类型派生的类型覆盖其基类中的属性? - Why can't a deriving class override a property in its base class with a type derived from the original type? 从CSharp中的基类对象访问派生类属性成员 - Accessing derived class property members from base class object in CSharp 如何通过Visual Studio中的“即时”窗口访问派生类的基类的成员? - How can I access members of a derived class's base class through the Immediate window in Visual Studio? 为什么我不能在没有强制转换的情况下访问基类的成员? - Why can I not access members of the base class without casting? 为什么派生类接口的引用显示基类的字段? - Why reference of derived class interface shows field of the base class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM