1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
namespace testExpressionCall
{
class Personne
{
public string Nom { get; set; }
public string Prenom { get; set; }
public double Age { get; set; }
}
class Program
{
static void Main(string[] args)
{
PropertyInfo propriete = typeof(Personne).GetProperty("Age");
MethodInfo methode = typeof(PropertyInfo).GetMethod("GetValue", new System.Type[] { typeof(object), typeof(object[]) });
var p = Expression.Parameter(typeof(object), "p");
object[] vide = new object[0];
Expression G = Expression.Call(
Expression.Constant(propriete),
methode,
p,
Expression.Constant(vide));
var lambda = Expression.Lambda<Func<Personne, object>>(G, p);
var predicat = lambda.Compile();
//MethodInfo test = typeof(Enumerable).GetMethod("Sum");
MethodInfo methodeFunction = typeof(Enumerable).GetMethod("Sum", new Type[] { typeof(IEnumerable<double>), typeof(Func<double, double>) });
Type T = G.Type;
Expression function = Expression.Call(null, methodeFunction, lambda);
Console.WriteLine(function.ToString());
//Assert
}
}
} |
Partager