Clarify that reflection member enumeration order is not guaranteed#130494
Conversation
Co-authored-by: steveisok <471438+steveisok@users.noreply.github.com>
|
This repo is not the source of truth for the documentation of these APIs. The official documentation documents this already. From https://learn.microsoft.com/en-us/dotnet/api/system.type.getevents : In .NET 6 and earlier versions, the GetEvents method does not return events in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which events are returned, because that order varies. However, starting with .NET 7, the ordering is deterministic based upon the metadata ordering in the assembly. |
I am not sure we want to make this guarantee. I think it would just encourage using reflection APIs in a fragile way. |
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection |
Thanks - should have looked there first ;-). |
Reflection APIs like
Type.GetMethods()currently appear to group members by inheritance depth, but that behavior is an implementation detail rather than a contract. This change makes the API docs explicit that callers should not depend on ordering across inherited members.Description
System.Typethat are commonly used for member enumeration:GetEventsGetFieldsGetMember(string)GetMembersGetMethodsGetPropertiesEffect on callers