Is there any reason why .NET's Reflection API

2019-09-15 08:47发布

问题:

Is there any reason why .NET's Reflection API uses arrays instead of indexers to access a type's members/methods/properties/etc.? I understand the overhead of adding collection objects classes such as MemberInfoCollection, MethodInfoCollection, etc. However, these collection objects classes could be created instantiated on demand. Was the design rationale something other than just "dissuade programmers from using Reflection unless they really need it"?

回答1:

These APIs were created in .Net 1.0, which didn't have generics.

They couldn't just return a ReadOnlyCollection<MemberInfo>, and they were too lazy to create a separate typed collection class for each type they need to return.

(I don't have a source for this belief)