Ejemplo n.º 1
0
        internal static DynamicMetaObject/*!*/ AddDynamicTestAndDefer(DynamicMetaObjectBinder/*!*/ operation, DynamicMetaObject/*!*/ res, DynamicMetaObject/*!*/[] args, ValidationInfo typeTest, Type deferType, params ParameterExpression[] temps)
        {
            if (typeTest != null && typeTest.Test != null)
            {
                // add the test and a validtor if present
                Expression defer = operation.GetUpdateExpression(deferType ?? typeof(object));

                Type bestType = BindingHelpers.GetCompatibleType(defer.Type, res.Expression.Type);

                res = new DynamicMetaObject(
                    Expression.Condition(
                        typeTest.Test,
                        Utils.Convert(res.Expression, bestType),
                        Utils.Convert(defer, bestType)
                    ),
                    res.Restrictions
                );
            }

            if (temps.Length > 0)
            {
                // finally add the scoped variables
                res = new DynamicMetaObject(
                    Expression.Block(temps, res.Expression),
                    res.Restrictions,
                    null
                );
            }

            return res;
        }
Ejemplo n.º 2
0
 internal static DynamicMetaObject AddDynamicTestAndDefer(DynamicMetaObjectBinder operation, DynamicMetaObject res, DynamicMetaObject[] args, ValidationInfo typeTest, params ParameterExpression[] temps)
 {
     return AddDynamicTestAndDefer(operation, res, args, typeTest, null, temps);
 }