35
1
using System;
2
using System.Linq.Expressions;
3
4
public class Program
5
{
6
public static void Main()
7
{
8
ParameterExpression pe = Expression.Parameter(typeof(Student), "s");
9
10
MemberExpression me = Expression.Property(pe, "Age");
11
12
ConstantExpression constant = Expression.Constant(18, typeof(int));
13
14
BinaryExpression body = Expression.GreaterThanOrEqual(me, constant);
15
16
var ExpressionTree = Expression.Lambda<Func<Student, bool>>(body, new[] { pe });
17
18
19
Console.WriteLine("Expression Tree: {0}", ExpressionTree);
20
21
Console.WriteLine("Expression Tree Body: {0}", ExpressionTree.Body);
22
23
Console.WriteLine("Number of Parameters in Expression Tree: {0}", ExpressionTree.Parameters.Count);
24
25
Console.WriteLine("Parameters in Expression Tree: {0}", ExpressionTree.Parameters[0]);
26
27
}
28
}
29
30
public class Student{
31
32
public int StudentID { get; set; }
33
public string StudentName { get; set; }
34
public int Age { get; set; }
35
}
Cached Result
hades
Robb
thanatos
osiris
ahpuch
Robb
thanatos
osiris
ahpuch