【发布时间】:2014-03-14 21:37:29
【问题描述】:
.NET 框架中的任何类或 MSDN 库中记录的任何其他库是否显式地实现了同一通用接口的两个实例化?
例如,以下类显式实现了IEnumerable<int> 和IEnumerable<string>。
public class T : IEnumerable<int>, IEnumerable<string>
{
IEnumerator<string> IEnumerable<string>.GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator<int> IEnumerable<int>.GetEnumerator()
{
throw new NotImplementedException();
}
}
对于任何想知道的人,我正在努力解决 Sandcastle 帮助文件生成器无法解析 MSDN 文档 URL 以继承显式实现的接口方法的问题。例如,扩展Dictionary<TKey, TValue> 的类继承ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue>) 的显式实现。使用MTPS查找该方法时,contentIdentifier如下:
AssetId:M:System.Collections.Generic.Dictionary`2.System#Collections#Generic#ICollection{T}#Contains(System.Collections.Generic.KeyValuePair{`0,`1 })
如果您注意到其中的粗体 T,您会发现此语法无法区分我在上面询问的具体情况。通过定位框架中的现有类,我可以使用 MTPS 服务来检查在这种特定类型的冲突情况下使用的内容标识符,从而确保我在这种肯定很少见但理论上可能的边缘情况下的行为正确。
【问题讨论】:
-
我相信您的基本问题的答案是
M:T.System#Collections#Generic#IEnumerable{System#Int32}#GetEnumerator和M:T.System#Collections#Generic#IEnumerable{System#String}#GetEnumerator
标签: .net generics msdn base-class-library