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)