using System.Collections.Generic;
using System.Linq.Expressions;
public int myProperty {get; set;}
public static void Main(string[] args)
TestClass obj = new TestClass();
Console.WriteLine("****************** C# Equivalent Output **************************\n\n");
Console.WriteLine("Property: {0}",obj.myProperty);
Console.WriteLine("Field: {0}",obj.myField);
Console.WriteLine("\n\n***************** Expression Tree Output **************************\n\n");
Expression propertyExpr = Expression.PropertyOrField(
Expression.Constant(obj),
Expression fieldExpr = Expression.PropertyOrField(
Expression.Constant(obj),
Console.WriteLine("Property: {0}",Expression.Lambda<Func<int>>(propertyExpr).Compile()());
Console.WriteLine("Field: {0}",Expression.Lambda<Func<int>>(fieldExpr).Compile()());