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


C# ErrorHandler.GetTypeName方法代码示例

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


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

示例1: GetTypeNameFor

 public static string GetTypeNameFor(TypeNode type, bool suppressTemplateParameters, bool fullName){
   if (type == null || type.Name == Looker.NotFound) return "";
   switch(type.TypeCode){
     case TypeCode.Boolean: return "bool";
     case TypeCode.Byte: return "byte";
     case TypeCode.Char: return "char";
     case TypeCode.Decimal: return "decimal";
     case TypeCode.Double: return "double";
     case TypeCode.Int16: return "short";
     case TypeCode.Int32: return "int";
     case TypeCode.Int64: return "long";
     case TypeCode.SByte: return "sbyte";
     case TypeCode.Single: return "float";
     case TypeCode.String: return "string";
     case TypeCode.UInt16: return "ushort";
     case TypeCode.UInt32: return "uint";
     case TypeCode.UInt64: return "ulong";
   }
   if (type == SystemTypes.Object) return "object";
   if (type == SystemTypes.Void) return "void";
   if (type.Template == SystemTypes.GenericNullable){
     if (type.TemplateArguments != null && type.TemplateArguments.Count > 0)
       return ErrorHandler.GetTypeNameFor(type.TemplateArguments[0]) + "?";
   }
   switch (type.NodeType){
     case NodeType.ArrayType:
       ArrayType aType = (ArrayType)type;
       StringBuilder sb = new StringBuilder(ErrorHandler.GetTypeNameFor(aType.ElementType));
       sb.Append('[');
       for (int i = 0, n = aType.Rank; i < n; i++){
         if (i == 0 && n > 1) sb.Append('*');
         if (i < n-1){
           sb.Append(',');
           if (n > 1) sb.Append('*');
         }
       }
       sb.Append(']');
       return sb.ToString();
     case NodeType.Class:
       FunctionType fType = type as FunctionType;
       if (fType != null){
         ErrorHandler eh = new ErrorHandler(new ErrorNodeList(0));
         return "delegate " + eh.GetTypeName(fType.ReturnType)+" "+eh.GetSignatureString("", fType.Parameters, "(", ")", ", ");
       }
       ClosureClass cClass = type as ClosureClass;
       if (cClass != null){
         MemberList mems = cClass.Members;
         for (int i = 0, n = mems == null ? 0 : mems.Count; i < n; i++){
           Method meth = mems[i] as Method;
           if (meth == null || meth is InstanceInitializer || (meth.Parameters != null && meth.Parameters.Count != 0)) continue;
           return ErrorHandler.GetTypeNameFor(meth.ReturnType);
         }
       }
       if (type.Template != null && type.TemplateArguments != null && type.TemplateArguments.Count > 0){
         sb = new StringBuilder(ErrorHandler.GetTypeNameFor(type.Template, true, fullName));
         for (int i = 0, n = type.TemplateArguments == null ? 0 : type.TemplateArguments.Count; i < n; i++){
           if (i == 0) sb.Append('<');
           sb.Append(ErrorHandler.GetTypeNameFor(type.TemplateArguments[i]));
           if (i < n - 1) sb.Append(','); else sb.Append('>');
         }
         return sb.ToString();
       }
       if (type.DeclaringType != null)
         sb = new StringBuilder(ErrorHandler.GetTypeNameFor(type.DeclaringType)+"."+type.GetUnmangledNameWithoutTypeParameters());
       else
         sb = new StringBuilder(type.GetFullUnmangledNameWithoutTypeParameters());
       if (!suppressTemplateParameters && type.TemplateParameters != null){
         for (int i = 0, n = type.TemplateParameters == null ? 0 : type.TemplateParameters.Count; i < n; i++){
           if (i == 0) sb.Append('<');
           sb.Append(ErrorHandler.GetTypeNameFor(type.TemplateParameters[i], false, fullName));
           if (i < n - 1) sb.Append(','); else sb.Append('>');
         }
         return sb.ToString();
       }
       return sb.ToString();
     case NodeType.ConstrainedType:
     case NodeType.DelegateNode:
     case NodeType.EnumNode:
     case NodeType.Interface:
     case NodeType.TypeAlias:
       goto case NodeType.Class;
     case NodeType.OptionalModifier:
       if (((OptionalModifier)type).Modifier == SystemTypes.NonNullType)
         return ErrorHandler.GetTypeNameFor(((OptionalModifier)type).ModifiedType)+"!";
       if (((OptionalModifier)type).Modifier == SystemTypes.NullableType)
         return ErrorHandler.GetTypeNameFor(((OptionalModifier)type).ModifiedType) + "?";
       goto case NodeType.RequiredModifier;
     case NodeType.RequiredModifier:
       return ErrorHandler.GetTypeNameFor(((TypeModifier)type).ModifiedType);
     case NodeType.Pointer:
       return ErrorHandler.GetTypeNameFor(((Pointer)type).ElementType)+"*";
     case NodeType.Reference:
       return "ref "+ErrorHandler.GetTypeNameFor(((Reference)type).ElementType);
     case NodeType.Refanytype:
     case NodeType.Struct:
       goto case NodeType.Class;
     case NodeType.ClassParameter:
     case NodeType.TypeParameter:
       return type.Name.ToString();
     case NodeType.ClassExpression : 
//.........这里部分代码省略.........
开发者ID:hesam,项目名称:SketchSharp,代码行数:101,代码来源:Error.cs


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