Last active
July 25, 2016 08:32
-
-
Save rogeralsing/3b8f94533dca6f65f676ef21311171ca to your computer and use it in GitHub Desktop.
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
var expressions = new List<Expression>(); | |
var newExpression = Expression.New(defaultCtor); | |
var targetObject = Expression.Variable(typeof(object),"target"); | |
var assignTarget = Expression.Assign(targetObject, newExpression); | |
var streamParam = Expression.Parameter(typeof(Stream)); | |
var sessionParam = Expression.Parameter(typeof(DeserializerSession)); | |
expressions.Add(assignTarget); | |
foreach (var r in fieldReaders) | |
{ | |
var c = Expression.Constant(r); | |
var i = Expression.Invoke(c, streamParam, targetObject, sessionParam); | |
expressions.Add(i); | |
} | |
var body = Expression.Block(expressions); | |
//TODO: how do I return targetObject from the block? | |
var readAllFields = Expression | |
.Lambda<ObjectReader>(body, streamParam, sessionParam) //this throws as the body is Void and the delegate returns Object | |
.Compile(); | |
return readAllFields; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment