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


C# ICSharpCode.NRefactory.CSharp.CastTo方法代码示例

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


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

示例1: Convert

        Ast.Expression Convert(Ast.Expression expr, Cecil.TypeReference actualType, Cecil.TypeReference reqType)
        {
            if (actualType == null || reqType == null || TypeAnalysis.IsSameType(actualType, reqType)) {
                return expr;
            } else if (actualType is ByReferenceType && reqType is PointerType && expr is DirectionExpression) {
                return Convert(
                    new UnaryOperatorExpression(UnaryOperatorType.AddressOf, ((DirectionExpression)expr).Expression.Detach()),
                    new PointerType(((ByReferenceType)actualType).ElementType),
                    reqType);
            } else if (actualType is PointerType && reqType is ByReferenceType) {
                expr = Convert(expr, actualType, new PointerType(((ByReferenceType)reqType).ElementType));
                return new DirectionExpression {
                    FieldDirection = FieldDirection.Ref,
                    Expression = new UnaryOperatorExpression(UnaryOperatorType.Dereference, expr)
                };
            } else if (actualType is PointerType && reqType is PointerType) {
                if (actualType.FullName != reqType.FullName)
                    return expr.CastTo(AstBuilder.ConvertType(reqType));
                else
                    return expr;
            } else {
                bool actualIsIntegerOrEnum = TypeAnalysis.IsIntegerOrEnum(actualType);
                bool requiredIsIntegerOrEnum = TypeAnalysis.IsIntegerOrEnum(reqType);

                if (TypeAnalysis.IsBoolean(reqType)) {
                    if (TypeAnalysis.IsBoolean(actualType))
                        return expr;
                    if (actualIsIntegerOrEnum) {
                        return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, AstBuilder.MakePrimitive(0, actualType));
                    } else {
                        return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, new NullReferenceExpression());
                    }
                }
                if (TypeAnalysis.IsBoolean(actualType) && requiredIsIntegerOrEnum) {
                    return new ConditionalExpression {
                        Condition = expr,
                        TrueExpression = AstBuilder.MakePrimitive(1, reqType),
                        FalseExpression = AstBuilder.MakePrimitive(0, reqType)
                    };
                }

                if (expr is PrimitiveExpression && !requiredIsIntegerOrEnum && TypeAnalysis.IsEnum(actualType))
                {
                    return expr.CastTo(AstBuilder.ConvertType(actualType));
                }

                bool actualIsPrimitiveType = actualIsIntegerOrEnum
                    || actualType.MetadataType == MetadataType.Single || actualType.MetadataType == MetadataType.Double;
                bool requiredIsPrimitiveType = requiredIsIntegerOrEnum
                    || reqType.MetadataType == MetadataType.Single || reqType.MetadataType == MetadataType.Double;
                if (actualIsPrimitiveType && requiredIsPrimitiveType) {
                    return expr.CastTo(AstBuilder.ConvertType(reqType));
                }
                return expr;
            }
        }
开发者ID:ichengzi,项目名称:SharpDevelop,代码行数:56,代码来源:AstMethodBodyBuilder.cs

示例2: Convert

        Ast.Expression Convert(Ast.Expression expr, Cecil.TypeReference actualType, Cecil.TypeReference reqType)
        {
            if (reqType == null || actualType == reqType) {
                return expr;
            } else {
                bool actualIsIntegerOrEnum = TypeAnalysis.IsIntegerOrEnum(actualType);
                bool requiredIsIntegerOrEnum = TypeAnalysis.IsIntegerOrEnum(reqType);

                if (TypeAnalysis.IsBoolean(reqType)) {
                    if (TypeAnalysis.IsBoolean(actualType))
                        return expr;
                    if (actualIsIntegerOrEnum) {
                        return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, MakePrimitive(0, actualType));
                    } else {
                        return new BinaryOperatorExpression(expr, BinaryOperatorType.InEquality, new NullReferenceExpression());
                    }
                }
                if (TypeAnalysis.IsBoolean(actualType) && requiredIsIntegerOrEnum) {
                    return new ConditionalExpression {
                        Condition = expr,
                        TrueExpression = MakePrimitive(1, reqType),
                        FalseExpression = MakePrimitive(0, reqType)
                    };
                }
                if (actualIsIntegerOrEnum && requiredIsIntegerOrEnum) {
                    return expr.CastTo(AstBuilder.ConvertType(reqType));
                }
                return expr;
            }
        }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:30,代码来源:AstMethodBodyBuilder.cs


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