TypeSpec ImportType (MetaType type, DynamicTypeReader dtype) { if (type.HasElementType) { var element = type.GetElementType (); ++dtype.Position; var spec = ImportType (element, dtype); if (type.IsArray) return ArrayContainer.MakeType (module, spec, type.GetArrayRank ()); if (type.IsByRef) return ReferenceContainer.MakeType (module, spec); if (type.IsPointer) return PointerContainer.MakeType (module, spec); throw new NotImplementedException ("Unknown element type " + type.ToString ()); } return CreateType (type, dtype, true); }
// TODO: fine tune this so that our output is less verbose. We need to figure // out a way to do this while not making things confusing. string FormatType(Type t) { if (t == null) { return(""); } string type = GetFullName(t); if (type == null) { return(t.ToString()); } if (!type.StartsWith("System.")) { if (type.IndexOf(".") == -1) { return(type); } if (t.GetNamespace() == this.t.GetNamespace()) { return(t.Name); } return(type); } if (t.HasElementType) { Type et = t.GetElementType(); if (t.IsArray) { return(FormatType(et) + " []"); } if (t.IsPointer) { return(FormatType(et) + " *"); } if (t.IsByRef) { return("ref " + FormatType(et)); } } switch (type) { case "System.Byte": return("byte"); case "System.SByte": return("sbyte"); case "System.Int16": return("short"); case "System.Int32": return("int"); case "System.Int64": return("long"); case "System.UInt16": return("ushort"); case "System.UInt32": return("uint"); case "System.UInt64": return("ulong"); case "System.Single": return("float"); case "System.Double": return("double"); case "System.Decimal": return("decimal"); case "System.Boolean": return("bool"); case "System.Char": return("char"); case "System.String": return("string"); case "System.Object": return("object"); case "System.Void": return("void"); } if (type.LastIndexOf(".") == 6) { return(type.Substring(7)); } // // If the namespace of the type is the namespace of what // we are printing (or is a member of one if its children // don't print it. This basically means that in C# we would // automatically get the namespace imported by virtue of the // namespace {} block. // if (this.t.Namespace != null && (this.t.Namespace.StartsWith(t.Namespace + ".") || t.Namespace == this.t.Namespace)) { return(type.Substring(t.Namespace.Length + 1)); } return(type); }
TypeSpec ImportType (MetaType type, DynamicTypeReader dtype) { if (type.HasElementType) { var element = type.GetElementType (); ++dtype.Position; var spec = ImportType (element, dtype); if (type.IsArray) return ArrayContainer.MakeType (module, spec, type.GetArrayRank ()); if (type.IsByRef) return ReferenceContainer.MakeType (module, spec); if (type.IsPointer) return PointerContainer.MakeType (module, spec); throw new NotImplementedException ("Unknown element type " + type.ToString ()); } TypeSpec compiled_type; if (compiled_types.TryGetValue (type, out compiled_type)) { if (compiled_type.BuiltinType == BuiltinTypeSpec.Type.Object && dtype.IsDynamicObject ()) return module.Compiler.BuiltinTypes.Dynamic; return compiled_type; } return CreateType (type, dtype, true); }
public override string ToString() => Type.ToString();
// TODO: fine tune this so that our output is less verbose. We need to figure // out a way to do this while not making things confusing. string FormatType (Type t) { if (t == null) return ""; string type = GetFullName (t); if (type == null) return t.ToString (); if (!type.StartsWith ("System.")) { if (type.IndexOf (".") == -1) return type; if (t.GetNamespace () == this.t.GetNamespace ()) return t.Name; return type; } if (t.HasElementType) { Type et = t.GetElementType (); if (t.IsArray) return FormatType (et) + " []"; if (t.IsPointer) return FormatType (et) + " *"; if (t.IsByRef) return "ref " + FormatType (et); } switch (type) { case "System.Byte": return "byte"; case "System.SByte": return "sbyte"; case "System.Int16": return "short"; case "System.Int32": return "int"; case "System.Int64": return "long"; case "System.UInt16": return "ushort"; case "System.UInt32": return "uint"; case "System.UInt64": return "ulong"; case "System.Single": return "float"; case "System.Double": return "double"; case "System.Decimal": return "decimal"; case "System.Boolean": return "bool"; case "System.Char": return "char"; case "System.String": return "string"; case "System.Object": return "object"; case "System.Void": return "void"; } if (type.LastIndexOf(".") == 6) return type.Substring(7); // // If the namespace of the type is the namespace of what // we are printing (or is a member of one if its children // don't print it. This basically means that in C# we would // automatically get the namespace imported by virtue of the // namespace {} block. // if (this.t.Namespace.StartsWith (t.Namespace + ".") || t.Namespace == this.t.Namespace) return type.Substring (t.Namespace.Length + 1); return type; }
/// <summary> /// Get the name of the type being represented /// </summary> public override string ToString() { return(Type.ToString()); }
public static void GetFullNameForStackTrace(StringBuilder sb, MethodBase mi) { var declaringType = mi.DeclaringType; if (declaringType.IsGenericType && !declaringType.IsGenericTypeDefinition) { declaringType = declaringType.GetGenericTypeDefinition(); } // Get generic definition var bindingflags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; foreach (var m in declaringType.GetMethods(bindingflags)) { if (m.MetadataToken == mi.MetadataToken) { mi = m; break; } } sb.Append(declaringType.ToString()); sb.Append("."); sb.Append(mi.Name); if (mi.IsGenericMethod) { Type[] gen_params = mi.GetGenericArguments(); sb.Append("["); for (int j = 0; j < gen_params.Length; j++) { if (j > 0) { sb.Append(","); } sb.Append(gen_params [j].Name); } sb.Append("]"); } ParameterInfo[] p = mi.GetParameters(); sb.Append(" ("); for (int i = 0; i < p.Length; ++i) { if (i > 0) { sb.Append(", "); } Type pt = p[i].ParameterType; if (pt.IsGenericType && !pt.IsGenericTypeDefinition) { pt = pt.GetGenericTypeDefinition(); } sb.Append(pt.ToString()); if (p [i].Name != null) { sb.Append(" "); sb.Append(p [i].Name); } } sb.Append(")"); }