1 Comment

  1. Alex G

    Regarding:

    // TODO: Check for “where” Limitation in the Generic Definition

    You should not check for the where, because the generic argument constraints aren’t actually used to resolve method overloads.

    This extension method has worked very well for me so far:

    public static MethodInfo GetGenericMethod(this Type type, string name, int genericArguments, params Type[] parameterTypes)
    {
    return (from method in type.GetMethods()
    where method.Name == name
    where parameterTypes.SequenceEqual(method.GetParameters().Select(p => p.ParameterType))
    where method.GetGenericArguments().Count() == genericArguments
    select method).Single();
    }

    In my case I need to keep the generic MethodInfo because I then call MakeGenericMethod() for each type I encounter while emitting IL into a dynamic method.

    Happy coding!

    Alex G

Leave a Reply

Your email address will not be published.

*