System.Dynamic.DynamicObject.MetaDynamic.ReferenceArgAssign C# (CSharp) Method

ReferenceArgAssign() private static method

Helper method for generating expressions that assign byRef call parameters back to their original variables
private static ReferenceArgAssign ( Expression callArgs, Expression args ) : Expression
callArgs System.Linq.Expressions.Expression
args System.Linq.Expressions.Expression
return System.Linq.Expressions.Expression
            private static Expression ReferenceArgAssign(Expression callArgs, Expression[] args) {
                ReadOnlyCollectionBuilder<Expression> block = null;

                for (int i = 0; i < args.Length; i++) {
                    ContractUtils.Requires(args[i] is ParameterExpression);
                    if (((ParameterExpression)args[i]).IsByRef) {
                        if (block == null)
                            block = new ReadOnlyCollectionBuilder<Expression>();

                        block.Add(
                            Expression.Assign(
                                args[i],
                                Expression.Convert(
                                    Expression.ArrayIndex(
                                        callArgs,
                                        Expression.Constant(i)
                                    ),
                                    args[i].Type
                                )
                            )
                        );
                    }
                }

                if (block != null)
                    return Expression.Block(block);
                else
                    return Expression.Empty();
            }