Microsoft.CSharp.RuntimeBinder.Semantics.CType.underlyingType C# (CSharp) Méthode

underlyingType() public méthode

public underlyingType ( ) : CType
Résultat CType
        public CType underlyingType()
        {
            if (IsAggregateType() && getAggregate().IsEnum())
                return getAggregate().GetUnderlyingType();
            return this;
        }

Usage Example

            private AggCastResult bindExplicitConversionFromEnumToDecimal(AggregateType aggTypeDest)
            {
                Debug.Assert(_typeSrc != null);
                Debug.Assert(aggTypeDest != null);
                Debug.Assert(aggTypeDest.isPredefType(PredefinedType.PT_DECIMAL));

                AggregateType underlyingType = _typeSrc.underlyingType() as AggregateType;

                // Need to first cast the source expr to its underlying type.

                Expr exprCast;

                if (_exprSrc == null)
                {
                    exprCast = null;
                }
                else
                {
                    ExprClass underlyingExpr = GetExprFactory().CreateClass(underlyingType);
                    _binder.bindSimpleCast(_exprSrc, underlyingExpr, out exprCast);
                }

                // There is always an implicit conversion from any integral type to decimal.

                if (exprCast.GetConst() != null)
                {
                    // Fold the constant cast if possible.
                    ConstCastResult result = _binder.bindConstantCast(exprCast, _exprTypeDest, _needsExprDest, out _exprDest, true);
                    if (result == ConstCastResult.Success)
                    {
                        return(AggCastResult.Success);  // else, don't fold and use a regular cast, below.
                    }
                    if (result == ConstCastResult.CheckFailure && 0 == (_flags & CONVERTTYPE.CHECKOVERFLOW))
                    {
                        return(AggCastResult.Abort);
                    }
                }

                // Conversions from integral types to decimal are always bound as a user-defined conversion.

                if (_needsExprDest)
                {
                    // According the language, this is a standard conversion, but it is implemented
                    // through a user-defined conversion. Because it's a standard conversion, we don't
                    // test the CONVERTTYPE.NOUDC flag here.

                    bool ok = _binder.bindUserDefinedConversion(exprCast, underlyingType, aggTypeDest, _needsExprDest, out _exprDest, false);
                    Debug.Assert(ok);
                }

                return(AggCastResult.Success);
            }