using System.Linq.Expressions;
public static void Main()
var pirulo = new Pirulo { StringProperty = "Hello", IntProperty = 123 };
Console.WriteLine(AnExpressionMethod(pirulo, x => x.StringProperty));
Console.WriteLine(AnExpressionMethod(pirulo, x => x.IntProperty));
Console.WriteLine(AfunctionMethod(pirulo, x => x.StringProperty));
Console.WriteLine(AfunctionMethod(pirulo, x => x.IntProperty));
public string StringProperty { get; set; }
public int IntProperty { get; set; }
public static object AnExpressionMethod<T>(T theObject, Expression<Func<T, object>> expression)
return expression.Compile().Invoke(theObject);
public static object AfunctionMethod<T>(T theObject, Func<T, object> expression)
return expression.Invoke(theObject);