BindNubValue() private method

private BindNubValue ( EXPR exprSrc ) : EXPR
exprSrc EXPR
return EXPR
Exemplo n.º 1
0
            private bool bindExplicitConversionFromNub()
            {
                Debug.Assert(_typeSrc != null);
                Debug.Assert(_typeDest != null);

                // If S and T are value types and there is a builtin conversion from S => T then there is an
                // explicit conversion from S? => T that throws on null.
                if (_typeDest.IsValType() && _binder.BindExplicitConversion(null, _typeSrc.StripNubs(), _exprTypeDest, _pDestinationTypeForLambdaErrorReporting, _flags | CONVERTTYPE.NOUDC))
                {
                    if (_needsExprDest)
                    {
                        Expr valueSrc = _exprSrc;
                        // This is a holdover from the days when you could have nullable of nullable.
                        // Can we remove this loop?
                        while (valueSrc.Type is NullableType)
                        {
                            valueSrc = _binder.BindNubValue(valueSrc);
                        }
                        Debug.Assert(valueSrc.Type == _typeSrc.StripNubs());
                        if (!_binder.BindExplicitConversion(valueSrc, valueSrc.Type, _exprTypeDest, _pDestinationTypeForLambdaErrorReporting, _needsExprDest, out _exprDest, _flags | CONVERTTYPE.NOUDC))
                        {
                            VSFAIL("BindExplicitConversion failed unexpectedly");
                            return(false);
                        }
                        if (_exprDest is ExprUserDefinedConversion udc)
                        {
                            udc.Argument = _exprSrc;
                        }
                    }
                    return(true);
                }

                if ((_flags & CONVERTTYPE.NOUDC) == 0)
                {
                    return(_binder.bindUserDefinedConversion(_exprSrc, _typeSrc, _typeDest, _needsExprDest, out _exprDest, false));
                }
                return(false);
            }
            private bool bindExplicitConversionFromNub()
            {
                Debug.Assert(typeSrc != null);
                Debug.Assert(typeDest != null);

                // If S and T are value types and there is a builtin conversion from S => T then there is an
                // explicit conversion from S? => T that throws on null.
                if (typeDest.IsValType() && binder.BindExplicitConversion(null, typeSrc.StripNubs(), exprTypeDest, m_pDestinationTypeForLambdaErrorReporting, flags | CONVERTTYPE.NOUDC))
                {
                    if (needsExprDest)
                    {
                        EXPR valueSrc = exprSrc;
                        // UNDONE: This is a holdover from the days when you could have nullable of nullable.
                        // UNDONE: Can we remove this loop?
                        while (valueSrc.type.IsNullableType())
                        {
                            valueSrc = binder.BindNubValue(valueSrc);
                        }
                        Debug.Assert(valueSrc.type == typeSrc.StripNubs());
                        if (!binder.BindExplicitConversion(valueSrc, valueSrc.type, exprTypeDest, m_pDestinationTypeForLambdaErrorReporting, needsExprDest, out exprDest, flags | CONVERTTYPE.NOUDC))
                        {
                            VSFAIL("BindExplicitConversion failed unexpectedly");
                            return(false);
                        }
                        if (exprDest.kind == ExpressionKind.EK_USERDEFINEDCONVERSION)
                        {
                            exprDest.asUSERDEFINEDCONVERSION().Argument = exprSrc;
                        }
                    }
                    return(true);
                }

                if ((flags & CONVERTTYPE.NOUDC) == 0)
                {
                    return(binder.bindUserDefinedConversion(exprSrc, typeSrc, typeDest, needsExprDest, out exprDest, false));
                }
                return(false);
            }
Exemplo n.º 3
0
            private bool bindExplicitConversionFromNub()
            {
                Debug.Assert(_typeSrc != null);
                Debug.Assert(_typeDest != null);

                // If S and T are value types and there is a builtin conversion from S => T then there is an
                // explicit conversion from S? => T that throws on null.
                if (_typeDest.IsValType() && _binder.BindExplicitConversion(null, _typeSrc.StripNubs(), _typeDest, _flags | CONVERTTYPE.NOUDC))
                {
                    if (_needsExprDest)
                    {
                        Expr valueSrc = _exprSrc;
                        if (valueSrc.Type is NullableType)
                        {
                            valueSrc = _binder.BindNubValue(valueSrc);
                        }

                        Debug.Assert(valueSrc.Type == _typeSrc.StripNubs());
                        if (!_binder.BindExplicitConversion(valueSrc, valueSrc.Type, _typeDest, _needsExprDest, out _exprDest, _flags | CONVERTTYPE.NOUDC))
                        {
                            Debug.Fail("BindExplicitConversion failed unexpectedly");
                            return(false);
                        }
                        if (_exprDest is ExprUserDefinedConversion udc)
                        {
                            udc.Argument = _exprSrc;
                        }
                    }
                    return(true);
                }

                if ((_flags & CONVERTTYPE.NOUDC) == 0)
                {
                    return(_binder.bindUserDefinedConversion(_exprSrc, _typeSrc, _typeDest, _needsExprDest, out _exprDest, false));
                }
                return(false);
            }