Пример #1
0
        private static ImmutableArray <Symbol> GetMembers(NamespaceOrTypeSymbol container, string qualifiedName, out NamespaceOrTypeSymbol lastContainer)
        {
            var parts = SplitMemberName(qualifiedName);

            lastContainer = container;
            for (int i = 0; i < parts.Length - 1; i++)
            {
                var nestedContainer = (NamespaceOrTypeSymbol)lastContainer.GetMember(parts[i]);
                if (nestedContainer == null)
                {
                    // If there wasn't a nested namespace or type with that name, assume it's a
                    // member name that includes dots (e.g. explicit interface implementation).
                    return(lastContainer.GetMembers(string.Join(".", parts.Skip(i))));
                }
                else
                {
                    lastContainer = nestedContainer;
                }
            }

            return(lastContainer.GetMembers(parts[parts.Length - 1]));
        }
Пример #2
0
        private static void GetSourceMemberSymbols(NamespaceOrTypeSymbol symbol, List <ISymbol> list, LocalSymbolDumper localDumper)
        {
            foreach (var memberSymbol in symbol.GetMembers())
            {
                list.Add(memberSymbol);

                switch (memberSymbol.Kind)
                {
                case SymbolKind.NamedType:
                case SymbolKind.Namespace:
                    GetSourceMemberSymbols((NamespaceOrTypeSymbol)memberSymbol, list, localDumper);
                    break;

                case SymbolKind.Method:
                    var method = (MethodSymbol)memberSymbol;
                    foreach (var parameter in method.Parameters)
                    {
                        list.Add(parameter);
                    }

                    if (localDumper != null)
                    {
                        localDumper.GetLocalSymbols(method, list);
                    }

                    break;

                case SymbolKind.Field:
                    if (localDumper != null)
                    {
                        localDumper.GetLocalSymbols((FieldSymbol)memberSymbol, list);
                    }

                    break;
                }
            }
        }
Пример #3
0
        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("}");
            }
        }
Пример #4
0
 public static Symbol ChildSymbol(this NamespaceOrTypeSymbol parent, string name)
 {
     return(parent.GetMembers(name).First());
 }
Пример #5
0
 public static Symbol GetMember(this NamespaceOrTypeSymbol symbol, string name)
 {
     return(symbol.GetMembers(name).Single());
 }