Skip to content

Instantly share code, notes, and snippets.

@hvitorino
Created March 16, 2012 14:28
Show Gist options
  • Select an option

  • Save hvitorino/2050297 to your computer and use it in GitHub Desktop.

Select an option

Save hvitorino/2050297 to your computer and use it in GitHub Desktop.
getter delegate
public static Delegate CreateGetter(PropertyInfo property)
{
var objParm = Expression.Parameter(property.DeclaringType, "o");
Type delegateType = typeof(Func<,>).MakeGenericType(property.DeclaringType, typeof(object));
var lambda = Expression.Lambda(delegateType, Expression.Convert(Expression.Property(objParm, property.Name), typeof(object)), objParm);
return lambda.Compile();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment