Question

Do any classes in the .NET framework, or any other library documented in the MSDN library, explicitly implement two instantiations of the same generic interface?

For example, the following class explicitly implements both IEnumerable<int> and 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();
    }
}

For anyone wondering, I'm working on addressing issues with Sandcastle Help File Builder failing to resolve the MSDN documentation URLs for inherited explicitly implemented interface methods. For example, classes which extend Dictionary<TKey, TValue> inherit the explicit implementation of ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue>). When using MTPS to look up this method, the contentIdentifier is the following:

AssetId:M:System.Collections.Generic.Dictionary`2.System#Collections#Generic#ICollection{T}#Contains(System.Collections.Generic.KeyValuePair{`0,`1})

If you note the bold T in there, you'll see that this syntax would not be able to distinguish between the specific case I am asking about above. By locating an existing class in the framework, I can use the MTPS service to examine the content identifiers being used in the case of this particular type of conflict, allowing me to ensure correct behavior for this surely rare but theoretically possible edge case.

Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top