I try to compare two type definitions. One definition is Func<,>
. The other is generic definition of Func<T,TResults>
which, I think, should be Func<,>
as well.
The comparison returns false:
using System;
using System.Reflection;
namespace ConsoleApplication4
{
public class Program
{
static Func<T, TResult> get_f2<T, TResult>()
{
return input => default(TResult);
}
static void Main(string[] args)
{
Func<int, int> f1 = x => 2 * x;
Type f1_def = f1.GetType().GetGenericTypeDefinition();
MethodInfo f2_maker = typeof(Program).GetMethod("get_f2", BindingFlags.NonPublic | BindingFlags.Static);
Type f2_def = f2_maker.ReturnType;
Console.WriteLine(f1_def.ToString() + " " + f2_def.ToString() + " " + (f1_def == f2_def).ToString());
Console.ReadLine();
}
}
}
I compiled it with .net 4.5.
The result is
System.Func`2[T,TResult] System.Func`2[T,TResult] False
Aucun commentaire:
Enregistrer un commentaire