vendredi 29 mai 2015

Correct Parameter Type for GetMethod

In the code below, how should I be setting the variable "paramType" so that it matches the method shown in the GetMethod() call?

The code below does NOT match the method in the sample class (methodInfo is null).

using System;
using System.Linq.Expressions;

public class MyClass<TClass>
{
    public void MyMethod<TMethod>( Expression<Func<TClass, TMethod>> expr )
    {
    }
}

class Program
{
    static void Main( string[] args )
    {
        var classType = typeof( MyClass<> );

        // What should this really be?
        var paramType = typeof( Expression<> ).MakeGenericType( typeof( Func<,> ) );

        var methodInfo = classType.GetMethod( "MyMethod", new Type[] { paramType } );
    }
}





Aucun commentaire:

Enregistrer un commentaire