private void AppendMembers(StringBuilder result, NamespaceOrTypeSymbol container, string indent) { string memberIndent; if (container is NamedTypeSymbol) { memberIndent = indent + " "; result.Append(indent); result.AppendLine("{"); AppendCustomAttributes(result, container, indent, inBlock: true); if (container.GetAttributes().Length > 0) { result.AppendLine(); } } else { memberIndent = indent; } foreach (var member in container.GetMembers().OrderBy(m => m.Name, System.StringComparer.InvariantCulture)) { switch (member.Kind) { case SymbolKind.NamedType: var namedType = (PENamedTypeSymbol)member; result.Append(memberIndent); result.Append(".class "); MetadataSignatureHelper.AppendTypeAttributes(result, namedType.Flags); result.Append(" "); result.Append(member); if (namedType.BaseType() != null) { result.AppendLine(); result.Append(memberIndent); result.Append(" extends "); result.Append(namedType.BaseType()); } if (namedType.Interfaces().Length > 0) { result.AppendLine(); result.Append(memberIndent); result.Append(" implements "); result.Append(string.Join(", ", namedType.Interfaces())); } result.AppendLine(); AppendMembers(result, namedType, memberIndent); break; case SymbolKind.Namespace: var ns = member as PENamespaceSymbol; if ((object)ns != null) { AppendMembers(result, ns, indent); } break; case SymbolKind.Method: var method = member as PEMethodSymbol; if ((object)method != null && method.AssociatedSymbol == null) { result.Append(memberIndent); result.Append(".method "); AppendMethod(result, method, memberIndent); AppendCustomAttributes(result, member, memberIndent, inBlock: false); } break; case SymbolKind.Field: var field = (PEFieldSymbol)member; result.Append(memberIndent); result.Append(".field "); MetadataSignatureHelper.AppendFieldAttributes(result, field.Flags); result.Append(" "); result.Append(field.Type); result.Append(" "); result.Append(member.Name); result.AppendLine(); AppendCustomAttributes(result, member, memberIndent, inBlock: false); break; case SymbolKind.Property: var property = (PEPropertySymbol)member; string propertyName; result.Append(memberIndent); result.Append(".property "); PropertyAttributes propertyAttrs; ((PEModuleSymbol)container.ContainingModule).Module.GetPropertyDefPropsOrThrow(property.Handle, out propertyName, out propertyAttrs); if (MetadataSignatureHelper.AppendPropertyAttributes(result, propertyAttrs)) { result.Append(" "); } result.Append(property.Type); result.Append(" "); result.Append(property.Name); result.AppendLine(); result.Append(memberIndent); result.AppendLine("{"); AppendCustomAttributes(result, member, memberIndent, inBlock: true); if (property.GetMethod != null) { result.Append(memberIndent); result.Append(" .get "); AppendMethod(result, (PEMethodSymbol)property.GetMethod, memberIndent); } if (property.SetMethod != null) { result.Append(memberIndent); result.Append(" .set "); AppendMethod(result, (PEMethodSymbol)property.SetMethod, memberIndent); } result.Append(memberIndent); result.AppendLine("}"); break; case SymbolKind.Event: var evnt = (PEEventSymbol)member; result.Append(memberIndent); result.Append(".event "); string eventName; EventAttributes eventAttrs; EntityHandle type; ((PEModuleSymbol)container.ContainingModule).Module.GetEventDefPropsOrThrow(evnt.Handle, out eventName, out eventAttrs, out type); if (MetadataSignatureHelper.AppendEventAttributes(result, eventAttrs)) { result.Append(" "); } result.Append(evnt.Type); result.Append(" "); result.Append(evnt.Name); result.AppendLine(); result.Append(memberIndent); result.Append("{"); result.AppendLine(); AppendCustomAttributes(result, member, memberIndent, inBlock: true); if (evnt.RemoveMethod != null) { result.Append(memberIndent); result.Append(" .removeon "); AppendMethod(result, (PEMethodSymbol)evnt.RemoveMethod, memberIndent); } if (evnt.AddMethod != null) { result.Append(memberIndent); result.Append(" .addon "); AppendMethod(result, (PEMethodSymbol)evnt.AddMethod, memberIndent); } result.Append(memberIndent); result.AppendLine("}"); break; } } if (container is NamedTypeSymbol) { result.Append(indent); result.AppendLine("}"); } }