Created
March 16, 2012 14:28
-
-
Save hvitorino/2050297 to your computer and use it in GitHub Desktop.
getter delegate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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