DebugMetaType(IMetadataImport importer, int token, CorType type) : base(importer, token) { m_Type = type; if (this.IsClass || this.IsValueType || this.IsArray){ ICorDebugTypeEnum typeEnum = null; type.Raw.EnumerateTypeParameters(out typeEnum); //foreach (ICorDebugType t in ){ // typeArguments.Add(DebugType.Create(process, t)); //} } }
public void Skip(int celt) { m_enum.Skip((uint)celt); m_ty = null; }
public void Reset() { if (m_enum != null) m_enum.Reset(); m_ty = null; }
// // IEnumerator interface // public bool MoveNext() { if (m_enum == null) return false; ICorDebugType[] a = new ICorDebugType[1]; uint c = 0; int r = m_enum.Next((uint)a.Length, a, out c); if (r == 0 && c == 1) // S_OK && we got 1 new element m_ty = new CorType(a[0]); else m_ty = null; return m_ty != null; }
//Yet to implements ??? bool IsNullableType(CorType ct) { if (ct.Type != CorElementType.ELEMENT_TYPE_VALUETYPE) return false; //MDbgModule m = m_process.Modules.Lookup(ct.Class.Module); String name = "";//m.Importer.GetType(ct.Class.Token).FullName; return name.Equals("System.Nullable`1"); }
// Print CorType to the given string builder. // Will print generic info. internal static void PrintCorType(StringBuilder sb, CorType ct) { switch (ct.Type) { case CorElementType.ELEMENT_TYPE_CLASS: case CorElementType.ELEMENT_TYPE_VALUETYPE: // We need to get the name from the metadata. We can get a cached metadata importer // from a MDbgModule, or we could get a new one from the CorModule directly. // Is this hash lookup to get a MDbgModule cheaper than just re-querying for the importer? CorClass cc = ct.Class; MetaType retType = new MetaType(new CorModule(cc.m_module).Importer, (int)cc.Token); string typeName = retType.Name; if (!Regex.IsMatch(typeName, @"^[a-zA-Z0-9_.]+$")) { typeName = "**UNK**"; } sb.Append(typeName); return; // Primitives case CorElementType.ELEMENT_TYPE_BOOLEAN: sb.Append("System.Boolean"); return; case CorElementType.ELEMENT_TYPE_CHAR: sb.Append("System.Char"); return; case CorElementType.ELEMENT_TYPE_I1: sb.Append("System.SByte"); return; case CorElementType.ELEMENT_TYPE_U1: sb.Append("System.Byte"); return; case CorElementType.ELEMENT_TYPE_I2: sb.Append("System.Int16"); return; case CorElementType.ELEMENT_TYPE_U2: sb.Append("System.UInt16"); return; case CorElementType.ELEMENT_TYPE_I4: sb.Append("System.Int32"); return; case CorElementType.ELEMENT_TYPE_U4: sb.Append("System.Uint32"); return; case CorElementType.ELEMENT_TYPE_I8: sb.Append("System.Int64"); return; case CorElementType.ELEMENT_TYPE_U8: sb.Append("System.UInt64"); return; case CorElementType.ELEMENT_TYPE_I: sb.Append("System.IntPtr"); return; case CorElementType.ELEMENT_TYPE_U: sb.Append("System.UIntPtr"); return; case CorElementType.ELEMENT_TYPE_R4: sb.Append("System.Single"); return; case CorElementType.ELEMENT_TYPE_R8: sb.Append("System.Double"); return; // Well known class-types. case CorElementType.ELEMENT_TYPE_OBJECT: sb.Append("System.Object"); return; case CorElementType.ELEMENT_TYPE_STRING: sb.Append("System.String"); return; // Special compound types. Based off first type-param case CorElementType.ELEMENT_TYPE_SZARRAY: case CorElementType.ELEMENT_TYPE_ARRAY: case CorElementType.ELEMENT_TYPE_BYREF: case CorElementType.ELEMENT_TYPE_PTR: CorType t = ct.FirstTypeParameter; PrintCorType(sb, t); switch (ct.Type) { case CorElementType.ELEMENT_TYPE_SZARRAY: sb.Append("[]"); return; case CorElementType.ELEMENT_TYPE_ARRAY: int rank = ct.Rank; sb.Append('['); for (int i = 0; i < rank - 1; i++) { sb.Append(','); } sb.Append(']'); return; case CorElementType.ELEMENT_TYPE_BYREF: sb.Append("&"); return; case CorElementType.ELEMENT_TYPE_PTR: sb.Append("*"); return; } return; case CorElementType.ELEMENT_TYPE_FNPTR: sb.Append("*(...)"); return; case CorElementType.ELEMENT_TYPE_TYPEDBYREF: sb.Append("typedbyref"); return; default: sb.Append("<unknown>"); return; } }
// Return class as a string. /// <summary> /// Creates a string representation of CorType. /// </summary> /// <param name="proc">A debugged process.</param> /// <param name="ct">A CorType object representing a type in the debugged process.</param> /// <returns>String representaion of the passed in type.</returns> public static string PrintCorType(CorType ct) { StringBuilder sb = new StringBuilder(); PrintCorType(sb, ct); return sb.ToString(); }