private bool IsLocalType(ITypeSignature typeSig) { typeSig = typeSig.GetDeclaringType(); if (typeSig == null) { return(true); } return(null == typeSig.ResolutionScope); }
public static TypeDeclaration ResolveDeclaringType(this ITypeSignature typeSig, IModule context, bool throwOnFailure = false) { TypeDeclaration type = null; var declaringTypeSig = typeSig.GetDeclaringType(); if (declaringTypeSig != null) { type = context.AssemblyManager.Resolve(declaringTypeSig, context, false) as TypeDeclaration; } if (type == null) { if (throwOnFailure) { throw new ResolveReferenceException(string.Format(SR.TypeResolveError, typeSig.ToReflectionString())); } return(null); } return(type); }
private void PrintType(ITypeSignature typeSig, IModule module, bool ignoreOwner) { switch (typeSig.ElementCode) { case TypeElementCode.Array: { PrintType(typeSig.ElementType, module, true); _builder.Append("["); int count = typeSig.ArrayDimensions.Count - 1; for (int i = 0; i < count; i++) { _builder.Append(","); } _builder.Append("]"); } break; case TypeElementCode.ByRef: { PrintType(typeSig.ElementType, module, true); _builder.Append("&"); } break; case TypeElementCode.CustomModifier: { PrintType(typeSig.ElementType, module, true); } break; case TypeElementCode.FunctionPointer: break; case TypeElementCode.GenericParameter: { bool isMethod; int position; typeSig.GetGenericParameter(out isMethod, out position); if (isMethod) { _builder.Append("!!"); } else { _builder.Append("!"); } _builder.Append(position); } break; case TypeElementCode.GenericType: { PrintDeclaringType(typeSig.DeclaringType, module); PrintGenericArguments(typeSig.GenericArguments, module); } break; case TypeElementCode.Pinned: { PrintType(typeSig.ElementType, module, true); } break; case TypeElementCode.Pointer: { PrintType(typeSig.ElementType, module, true); _builder.Append("*"); } break; case TypeElementCode.DeclaringType: { PrintDeclaringType(typeSig, module); } break; default: throw new InvalidOperationException(); } if (!ignoreOwner) { typeSig = typeSig.GetDeclaringType(); if (typeSig != null) { var owner = typeSig.ResolutionScope; if (owner != null) { _builder.Append(", "); PrintAssembly((IAssemblySignature)owner); } else if (module != null && module.IsPrimeModule) { _builder.Append(", "); PrintAssembly(module.Assembly); } } } }