Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The order by extensions methods in QueryableExtensions and EnumerableExtensions should be cached #696

Open
johelvisguzman opened this issue Sep 30, 2022 · 0 comments
Labels
enhancement Updates existing code to be simpler, more powerful or adds somehow to existing functionality

Comments

@johelvisguzman
Copy link
Owner

private static readonly MethodInfo _first = GetMethod(
            "First", (T) => new[]
                {
                    typeof(IQueryable<>).MakeGenericType(T)
                });

private static MethodInfo GetMethod(string methodName, MethodInfo getParameterTypesMethod, int genericArgumentsCount)
{
    var candidates = typeof(Queryable).GetMember(methodName, MemberTypes.Method, BindingFlags.Public | BindingFlags.Static);

    foreach (MethodInfo candidate in candidates)
    {
        var genericArguments = candidate.GetGenericArguments();
        if (genericArguments.Length == genericArgumentsCount
            && Matches(candidate, (Type[])getParameterTypesMethod.Invoke(null, genericArguments)))
        {
            return candidate;
        }
    }

    return null;
}

private static MethodInfo GetMethod(string methodName, Func<Type[]> getParameterTypes)
{
    return GetMethod(methodName, getParameterTypes.Method, 0);
}
@johelvisguzman johelvisguzman added the enhancement Updates existing code to be simpler, more powerful or adds somehow to existing functionality label Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Updates existing code to be simpler, more powerful or adds somehow to existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant