Created
September 29, 2014 21:55
-
-
Save paavohuhtala/b20b2e8c422501a680f5 to your computer and use it in GitHub Desktop.
it's a lot shorter though
This file contains 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
static Delegate WrapGetter(PropertyInfo prop) | |
{ | |
var handle = Expression.Parameter(typeof (GCHandle), "handle"); | |
var boxedTarget = Expression.Property(handle, "Target"); | |
var unboxedTarget = Expression.Convert(boxedTarget, prop.DeclaringType); | |
var targetValue = Expression.Property(unboxedTarget, prop); | |
var wrapperBase = typeof(Func<,>); | |
var wrapperDelegate = wrapperBase.MakeGenericType(typeof(GCHandle), prop.PropertyType); | |
return Expression.Lambda(wrapperDelegate, targetValue, handle).Compile(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment