Why does the VS Metadata view does not display explicit interface implemented members

前端 未结 4 1161
盖世英雄少女心
盖世英雄少女心 2020-12-11 17:41

The other day i was looking at C# Boolean struct metadata.

Boolean implements the interface IConvertible. But looking at Boolean\'s members i could not see most of t

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 18:06

    The metadata does indeed show the explicitly implemented. Do you mean intellisense and not metadata?

    I'd say that's by design and help the developer of say Boolean to restrict the interface to a subset. By restricting what's suggested to use it also becomes visible what's considered abnormal usage. E.g. it's generally not advised to view a Boolean value as a specific numeric value but in certain cases it's handy to be able to do that anyways.

    IDictinary is another example. It implements IEnumerable> making it possible to iterate over all the pairs in the collection and ICollation>. So you can call Add on the dictionary given a KeyValuePair but usually you should use Add(K, key, T Value)

    Try inspecting the class with a tool that provides read access to metadata. ILDASM for one and you can indeed find metadata of the explicitly implemented methods.

提交回复
热议问题