当前位置: 首页>>代码示例>>C#>>正文


C# EXPR.asCAST方法代码示例

本文整理汇总了C#中Microsoft.CSharp.RuntimeBinder.Semantics.EXPR.asCAST方法的典型用法代码示例。如果您正苦于以下问题:C# EXPR.asCAST方法的具体用法?C# EXPR.asCAST怎么用?C# EXPR.asCAST使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CSharp.RuntimeBinder.Semantics.EXPR的用法示例。


在下文中一共展示了EXPR.asCAST方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetObject

        /////////////////////////////////////////////////////////////////////////////////

        private object GetObject(EXPR pExpr)
        {
            if (pExpr.isCAST())
            {
                return GetObject(pExpr.asCAST().GetArgument());
            }
            else if (pExpr.isTYPEOF())
            {
                return pExpr.asTYPEOF().SourceType.type.AssociatedSystemType;
            }
            else if (pExpr.isMETHODINFO())
            {
                return GetMethodInfoFromExpr(pExpr.asMETHODINFO());
            }
            else if (pExpr.isCONSTANT())
            {
                CONSTVAL val = pExpr.asCONSTANT().Val;
                CType underlyingType = pExpr.type;
                object objval;

                if (pExpr.type.IsNullType())
                {
                    return null;
                }

                if (pExpr.type.isEnumType())
                {
                    underlyingType = underlyingType.getAggregate().GetUnderlyingType();
                }

                switch (underlyingType.AssociatedSystemType.GetTypeCode())
                {
                    case TypeCode.Boolean:
                        objval = val.boolVal;
                        break;
                    case TypeCode.SByte:
                        objval = val.sbyteVal;
                        break;
                    case TypeCode.Byte:
                        objval = val.byteVal;
                        break;
                    case TypeCode.Int16:
                        objval = val.shortVal;
                        break;
                    case TypeCode.UInt16:
                        objval = val.ushortVal;
                        break;
                    case TypeCode.Int32:
                        objval = val.iVal;
                        break;
                    case TypeCode.UInt32:
                        objval = val.uiVal;
                        break;
                    case TypeCode.Int64:
                        objval = val.longVal;
                        break;
                    case TypeCode.UInt64:
                        objval = val.ulongVal;
                        break;
                    case TypeCode.Single:
                        objval = val.floatVal;
                        break;
                    case TypeCode.Double:
                        objval = val.doubleVal;
                        break;
                    case TypeCode.Decimal:
                        objval = val.decVal;
                        break;
                    case TypeCode.Char:
                        objval = val.cVal;
                        break;
                    case TypeCode.String:
                        objval = val.strVal;
                        break;
                    default:
                        objval = val.objectVal;
                        break;
                }

                if (pExpr.type.isEnumType())
                {
                    objval = Enum.ToObject(pExpr.type.AssociatedSystemType, objval);
                }

                return objval;
            }
            else if (pExpr.isZEROINIT())
            {
                if (pExpr.asZEROINIT().OptionalArgument != null)
                {
                    return GetObject(pExpr.asZEROINIT().OptionalArgument);
                }
                return System.Activator.CreateInstance(pExpr.type.AssociatedSystemType);
            }

            Debug.Assert(false, "Invalid EXPR in GetObject");
            throw Error.InternalCompilerError();
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:100,代码来源:ExpressionTreeCallRewriter.cs

示例2: GenerateQuestionMarkOperand

 protected virtual EXPR GenerateQuestionMarkOperand(EXPR pExpr)
 {
     Debug.Assert(pExpr != null);
     // We must not optimize away compiler-generated reference casts because
     // the expression tree API insists that the CType of both sides be identical.
     if (pExpr.isCAST())
     {
         return GenerateConversion(pExpr.asCAST().GetArgument(), pExpr.type, pExpr.isChecked());
     }
     return Visit(pExpr);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:11,代码来源:ExpressionTreeRewriter.cs

示例3: operator

        /*
            Handles enum unary operator (~).
        */
        private EXPR BindEnumUnaOp(ExpressionKind ek, EXPRFLAG flags, EXPR arg)
        {
            Debug.Assert(ek == ExpressionKind.EK_BITNOT);
            Debug.Assert(arg.isCAST());
            Debug.Assert(arg.asCAST().GetArgument().type.isEnumType());

            PredefinedType ptOp;
            CType typeEnum = arg.asCAST().GetArgument().type;

            switch (typeEnum.fundType())
            {
                default:
                    // Promote all smaller types to int.
                    ptOp = PredefinedType.PT_INT;
                    break;
                case FUNDTYPE.FT_U4:
                    ptOp = PredefinedType.PT_UINT;
                    break;
                case FUNDTYPE.FT_I8:
                    ptOp = PredefinedType.PT_LONG;
                    break;
                case FUNDTYPE.FT_U8:
                    ptOp = PredefinedType.PT_ULONG;
                    break;
            }

            CType typeOp = GetReqPDT(ptOp);
            arg = mustCast(arg, typeOp, CONVERTTYPE.NOUDC);

            EXPR exprRes = BindIntOp(ek, flags, arg, null, ptOp);

            if (!exprRes.isOK())
            {
                return exprRes;
            }

            return mustCastInUncheckedContext(exprRes, typeEnum, CONVERTTYPE.NOUDC);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:41,代码来源:Operators.cs


注:本文中的Microsoft.CSharp.RuntimeBinder.Semantics.EXPR.asCAST方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。