public void ReturnObject(ParameterExpression variable) { LabelTarget returnLabel = ExpressionFactory.Label(variable.Type); BodyExpressions.Add(ExpressionFactory.Return(returnLabel, variable)); BodyExpressions.Add(ExpressionFactory.Label(returnLabel, variable)); }
public ParameterExpression CreateObject <TEntity>(string name, Type[] constructorTypes, Expression[] constructorValues) { ConstructorInfo constructor = typeof(TEntity).GetConstructor(constructorTypes); ParameterExpression variableExpression = AddVariable <TEntity>(name); Expression createObjectExpression = ExpressionFactory.Assign( variableExpression, ExpressionFactory.New( constructor, constructorValues)); BodyExpressions.Add(createObjectExpression); return(variableExpression); }
public void For(Expression collectionExpression, Func <ParameterExpression, Expression> contentExpressionDelegate) { ParameterExpression iteratorVariable = ExpressionFactory.Variable <int>(nameof(iteratorVariable)); LabelTarget breakLabel = ExpressionFactory.Label(nameof(breakLabel)); Expression forBlock = ExpressionFactory.Block( new[] { iteratorVariable }, ExpressionFactory.Loop( ExpressionFactory.IfThenElse( ExpressionFactory.LessThan( iteratorVariable, ExpressionFactory.Call( collectionExpression, CollectionCountProperty.GetMethod)), ExpressionFactory.Block( contentExpressionDelegate(iteratorVariable), ExpressionFactory.PostIncrementAssign(iteratorVariable)), ExpressionFactory.Break(breakLabel)), breakLabel) ); BodyExpressions.Add(forBlock); }
public void SetProperty(ParameterExpression variable, PropertyInfo property, Expression value) => BodyExpressions.Add(ExpressionFactory.Call(variable, property.SetMethod, value));