using System.Linq.Expressions;
public static void Main()
Console.WriteLine("****************** C# Equivalent Output **************************\n\n");
Employee e = new Employee();
object objEmp = e as object;
Console.WriteLine("It is an Empoyee object");
Console.WriteLine("It is not an Empoyee object");
Console.WriteLine("\n\n***************** Expression Tree Output **************************\n\n");
TypeBinaryExpression testCondition = Expression.TypeIs(
Expression.Constant(objEmp),
var ifTrueBlock = WriteLineExpression("It is an Empoyee object");
var ifFalseBlock = WriteLineExpression("It is not an Empoyee object");
var ifThenExpr = Expression.IfThenElse(testCondition, ifTrueBlock, ifFalseBlock);
Expression.Lambda<Action>(ifThenExpr).Compile()();
public static Expression WriteLineExpression(string s)
return Expression.Call(null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
public string Name { get; set; }
public DateTime BirthDate { get; set; }