3

I was looking at the metadata generated for IDictionary<TKey, TValue> interface and I noticed it implements

public interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable

Isn't this redundant? Looking at the metadata of ICollection<T> it shows that it already implements IEnumerable<T>, IEnumerable

And why does IEnumerable<T> implments IEnumerable, while ICollection<T> doesn't implement ICollection?

nicecatch
  • 1,687
  • 2
  • 21
  • 38
  • Have you read this post https://stackoverflow.com/questions/46541462/explicitly-marking-derived-class-as-implementing-interface-of-base-class? – MakePeaceGreatAgain May 04 '18 at 08:41
  • Metadata lists all implemented interfaces, whether directly or indirectly. Second question has answer here: https://stackoverflow.com/q/2353346/5311735 – Evk May 04 '18 at 08:41

2 Answers2

4

The metadata show all implemented interfaces, especially those obtained through inheritance. If you look into the reference source of IDictionary<TKey, TValue>, you see that the actual implementation only implements ICollection<KeyValuePair<TKey, TValue>>:

public interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>
adjan
  • 13,371
  • 2
  • 31
  • 48
  • So it is just showing all the interfaces it is implementing (recursively), not just the ones that are declared explicity – nicecatch May 04 '18 at 12:21
0

Read this. It explains everything you want to know about your first question.

I quote the most relevant part:

Why do tools like Reflector or the object browser show the whole list?

Those tools do not have the source code. They only have metadata to work from. Since putting in the full list is optional, the tool has no idea whether the original source code contains the full list or not. It is better to err on the side of more information. Again, the tool is attempting to help you by showing you more information rather than hiding information you might need.

InBetween
  • 32,319
  • 3
  • 50
  • 90