Skip to content

Commit

Permalink
SortExtensionMethods improved to return the most relevant method
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelbaran authored and Fraser Greenroyd committed Feb 24, 2021
1 parent 4c4505f commit b3a740b
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions Reflection_Engine/Modify/SortExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ public static partial class Modify
[Output("metods", "Sorted methods")]
public static List<MethodInfo> SortExtensionMethods(this IEnumerable<MethodInfo> methods, Type type)
{
//TODO: Sort methods based on closeness to the type, not just exact vs non exact.
//Example A : B and B : C
//Then if the type is A and list of methods contain one method with first parameter matching each type, then the list should be
//Sorted so that the method with A comes first followed by B and lastly C.
return methods.OrderBy(x => x.GetParameters().FirstOrDefault()?.ParameterType == type ? 0 : 1).ToList();
return methods.OrderBy(x => methods.Count(y => x.GetParameters()[0].ParameterType.IsAssignableFrom(y.GetParameters()[0].ParameterType))).ToList();
}

/***************************************************/
Expand Down

0 comments on commit b3a740b

Please sign in to comment.