[英]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.