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


C# Expression.GetType方法代码示例

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


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

示例1: GetType

 public TypeReference GetType(Expression ex, INode parent)
 {
     if (ex is IdentifierExpression)
     {
         return GetIdentifierType(ex, parent);
     }
     else if (ex is FieldReferenceExpression)
     {
         FieldReferenceExpression fieldReference = (FieldReferenceExpression) ex;
         Expression targetObject = fieldReference.TargetObject;
         TypeReference targetType = GetType(targetObject);
         if (targetType != null)
         {
             string fullName = TypeResolver.GetFullName(targetType);
             if (targetType.RankSpecifier != null && targetType.RankSpecifier.Length > 0 && !(ex.Parent is IndexerExpression))
                 fullName = "JavaArray";
             if (CodeBase.Types.Contains(fullName))
             {
                 TypeDeclaration typeDeclaration = (TypeDeclaration) CodeBase.Types[fullName];
                 if (typeDeclaration.Type == ClassType.Enum)
                     return AstUtil.GetTypeReference(typeDeclaration.Name, ex.Parent);
                 else
                     return GetTypeInMembers(typeDeclaration, fieldReference.FieldName);
             }
         }
         return null;
     }
     else if (ex is PrimitiveExpression)
     {
         return GetConstantType((PrimitiveExpression) ex);
     }
     else if (ex is InvocationExpression)
     {
         return GetType(((InvocationExpression) ex).TargetObject);
     }
     else if (ex is IndexerExpression)
     {
         return GetType(((IndexerExpression) ex).TargetObject);
     }
     else if (ex is BinaryOperatorExpression)
     {
         return GetType(((BinaryOperatorExpression) ex).Left);
     }
     else if (ex is ObjectCreateExpression)
     {
         return ((ObjectCreateExpression) ex).CreateType;
     }
     else if (ex is ThisReferenceExpression)
     {
         TypeDeclaration ty = (TypeDeclaration) AstUtil.GetParentOfType(ex, typeof(TypeDeclaration));
         return AstUtil.GetTypeReference(ty.Name, ex.Parent);
     }
     else if (ex is CastExpression)
     {
         CastExpression cast = (CastExpression) ex;
         return cast.CastTo;
     }
     else if (ex is ArrayCreateExpression)
     {
         return ((ArrayCreateExpression) ex).CreateType;
     }
     else if (ex is BaseReferenceExpression)
     {
         TypeDeclaration typeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(ex, typeof(TypeDeclaration));
         if (typeDeclaration.BaseTypes.Count > 0)
             return (TypeReference) typeDeclaration.BaseTypes[0];
         else
             return AstUtil.GetTypeReference("System.Object", parent);
     }
     else if (ex is ParenthesizedExpression)
     {
         return GetType(((ParenthesizedExpression) ex).Expression);
     }
     else if (ex is TypeReferenceExpression)
     {
         return ((TypeReferenceExpression) ex).TypeReference;
     }
     else if (ex is AssignmentExpression)
     {
         return GetType(((AssignmentExpression) ex).Left);
     }
     else if (ex is UnaryOperatorExpression)
     {
         return GetType(((UnaryOperatorExpression) ex).Expression);
     }
     else if (ex is TypeOfExpression)
     {
         TypeReference typeReference = new TypeReference("java.lang.Class");
         typeReference.Parent = parent;
         return typeReference;
     }
     else if (ex is TypeOfIsExpression)
     {
         return GetType(((TypeOfIsExpression) ex).Expression);
     }
     else if (ex is ConditionalExpression)
     {
         return GetType(((ConditionalExpression) ex).TrueExpression);
     }
     else if (ex is ParameterDeclarationExpression)
//.........这里部分代码省略.........
开发者ID:sourcewarehouse,项目名称:janett,代码行数:101,代码来源:ExpressionTypeResolver.cs


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