GetCompatibleType() static private méthode

static private GetCompatibleType ( Type t, Type otherType ) : Type
t System.Type
otherType System.Type
Résultat System.Type
Exemple #1
0
        internal static DynamicMetaObject /*!*/ AddDynamicTestAndDefer(DynamicMetaObjectBinder /*!*/ operation, DynamicMetaObject /*!*/ res, DynamicMetaObject /*!*/[] args, ValidationInfo typeTest, Type deferType, params ParameterExpression[] temps)
        {
            if (typeTest != null)
            {
                if (typeTest.Test != null)
                {
                    // add the test and a validator if persent
                    Expression defer = operation.GetUpdateExpression(deferType ?? typeof(object));

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

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

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

            return(res);
        }
        private DynamicMetaObject /*!*/ MakeConvertToBool(DynamicMetaObjectBinder /*!*/ conversion)
        {
            DynamicMetaObject self = Restrict(typeof(OldInstance));

            ParameterExpression tmp      = Ast.Variable(typeof(bool?), "tmp");
            DynamicMetaObject   fallback = FallbackConvert(conversion);
            Type resType = BindingHelpers.GetCompatibleType(typeof(bool), fallback.Expression.Type);

            return(new DynamicMetaObject(
                       Ast.Block(
                           new ParameterExpression[] { tmp },
                           Ast.Condition(
                               Ast.NotEqual(
                                   Ast.Assign(
                                       tmp,
                                       Ast.Call(
                                           typeof(PythonOps).GetMethod(nameof(PythonOps.OldInstanceConvertToBoolNonThrowing)),
                                           AstUtils.Constant(PythonContext.GetPythonContext(conversion).SharedContext),
                                           self.Expression
                                           )
                                       ),
                                   AstUtils.Constant(null)
                                   ),
                               AstUtils.Convert(tmp, resType),
                               AstUtils.Convert(fallback.Expression, resType)
                               )
                           ),
                       self.Restrictions
                       ));
        }