The Run2 method is run. But the Run method is not run. What is the reason ? The only difference between two methods is because parameter.
public class MyClass
{
public string Name { get; set; }
}
[TestFixture]
public class Test
{
public IEnumerable<T> TestMethod<T>(int i)
{
//do something
return null;
}
public IEnumerable<T> TestMethod2<T>()
{
//do something
return null;
}
[Test]
public void Run()
{
MethodInfo mi = this.GetType().GetMethod("TestMethod").MakeGenericMethod(typeof(MyClass));
var del = Delegate.CreateDelegate(typeof(Func<IEnumerable<MyClass>>), this, mi);
var list = (IEnumerable<MyClass>)del.DynamicInvoke(0);
}
[Test]
public void Run2()
{
MethodInfo mi = this.GetType().GetMethod("TestMethod2").MakeGenericMethod(typeof(MyClass));
var del = Delegate.CreateDelegate(typeof(Func<IEnumerable<MyClass>>), this, mi);
var list = (IEnumerable<MyClass>)del.DynamicInvoke();
}
}