Beispiel #1
0
        public override MetadataItem VisitAssembly(IAssemblySymbol symbol)
        {
            var item = new MetadataItem
            {
                Name       = VisitorHelper.GetId(symbol),
                RawComment = symbol.GetDocumentationCommentXml(),
                Language   = Language,
            };

            item.DisplayNames = new SortedList <SyntaxLanguage, string>
            {
                { SyntaxLanguage.Default, symbol.MetadataName },
            };
            item.DisplayQualifiedNames = new SortedList <SyntaxLanguage, string>
            {
                { SyntaxLanguage.Default, symbol.MetadataName },
            };
            item.Type   = MemberType.Assembly;
            _references = new Dictionary <string, ReferenceItem>();
            var namespaces = symbol.GlobalNamespace.GetNamespaceMembers().ToList();

            if (namespaces.Count == 0)
            {
                Logger.LogWarning($"No namespace is found in assembly {symbol.MetadataName}. DocFX currently only supports generating metadata with namespace defined.");
            }

            item.Items = VisitDescendants(
                namespaces,
                ns => ns.GetMembers().OfType <INamespaceSymbol>(),
                ns => ns.GetMembers().OfType <INamedTypeSymbol>().Any(t => VisitorHelper.CanVisit(t)));
            item.References = _references;
            return(item);
        }
Beispiel #2
0
        private void GenerateInheritance(INamedTypeSymbol symbol, MetadataItem item)
        {
            Dictionary <string, string> dict = null;

            if (symbol.TypeKind == TypeKind.Class || symbol.TypeKind == TypeKind.Struct)
            {
                var type        = symbol;
                var inheritance = new List <string>();
                dict = new Dictionary <string, string>();
                var typeParamterNames = symbol.IsGenericType ? symbol.Accept(TypeGenericParameterNameVisitor.Instance) : EmptyListOfString;
                while (type != null)
                {
                    // TODO: special handles for errorType: change to System.Object
                    if (type.Kind == SymbolKind.ErrorType)
                    {
                        inheritance.Add("System.Object");
                        break;
                    }

                    if (type != symbol)
                    {
                        inheritance.Add(AddSpecReference(type, typeParamterNames));
                    }

                    AddInheritedMembers(symbol, type, dict, typeParamterNames);
                    type = type.BaseType;
                }

                if (symbol.TypeKind == TypeKind.Class)
                {
                    inheritance.Reverse();
                    item.Inheritance = inheritance;
                }
                if (symbol.AllInterfaces.Length > 0)
                {
                    item.Implements = (from t in symbol.AllInterfaces
                                       where VisitorHelper.CanVisit(t)
                                       select AddSpecReference(t, typeParamterNames)).ToList();
                    if (item.Implements.Count == 0)
                    {
                        item.Implements = null;
                    }
                }
            }
            else if (symbol.TypeKind == TypeKind.Interface)
            {
                dict = new Dictionary <string, string>();
                var typeParamterNames = symbol.IsGenericType ? symbol.Accept(TypeGenericParameterNameVisitor.Instance) : EmptyListOfString;
                AddInheritedMembers(symbol, symbol, dict, typeParamterNames);
                for (int i = 0; i < symbol.AllInterfaces.Length; i++)
                {
                    AddInheritedMembers(symbol, symbol.AllInterfaces[i], dict, typeParamterNames);
                }
            }
            if (dict != null)
            {
                var inheritedMembers = (from r in dict.Values where r != null select r).ToList();
                item.InheritedMembers = inheritedMembers.Count > 0 ? inheritedMembers : null;
            }
        }
Beispiel #3
0
        public override MetadataItem VisitAssembly(IAssemblySymbol symbol)
        {
            var item = new MetadataItem
            {
                Name       = VisitorHelper.GetId(symbol),
                RawComment = symbol.GetDocumentationCommentXml(),
                Language   = Language,
            };

            item.DisplayNames = new SortedList <SyntaxLanguage, string>
            {
                { SyntaxLanguage.Default, symbol.MetadataName },
            };
            item.DisplayQualifiedNames = new SortedList <SyntaxLanguage, string>
            {
                { SyntaxLanguage.Default, symbol.MetadataName },
            };
            item.Type   = MemberType.Assembly;
            _references = new Dictionary <string, ReferenceItem>();
            item.Items  = VisitDescendants(
                symbol.GlobalNamespace.GetNamespaceMembers(),
                ns => ns.GetMembers().OfType <INamespaceSymbol>(),
                ns => ns.GetMembers().OfType <INamedTypeSymbol>().Any(t => VisitorHelper.CanVisit(t)));
            item.References = _references;
            return(item);
        }
Beispiel #4
0
        public override MetadataItem DefaultVisit(ISymbol symbol)
        {
            if (!VisitorHelper.CanVisit(symbol))
            {
                return(null);
            }
            var item = new MetadataItem
            {
                Name       = VisitorHelper.GetId(symbol),
                RawComment = symbol.GetDocumentationCommentXml(),
                Language   = Language,
            };

            item.DisplayNames          = new SortedList <SyntaxLanguage, string>();
            item.DisplayQualifiedNames = new SortedList <SyntaxLanguage, string>();
            item.Source = VisitorHelper.GetSourceDetail(symbol);
            var assemblyName = symbol.ContainingAssembly?.Name;

            item.AssemblyNameList = string.IsNullOrEmpty(assemblyName) ? null : new List <string> {
                assemblyName
            };
            if (!(symbol is INamespaceSymbol))
            {
                var namespaceName = VisitorHelper.GetId(symbol.ContainingNamespace);
                item.NamespaceName = string.IsNullOrEmpty(namespaceName) ? null : namespaceName;
            }

            VisitorHelper.FeedComments(item, GetTripleSlashCommentParserContext(item, _preserveRawInlineComments));
            if (item.Exceptions != null)
            {
                foreach (var exceptions in item.Exceptions)
                {
                    AddReference(exceptions.Type);
                }
            }

            if (item.Sees != null)
            {
                foreach (var i in item.Sees)
                {
                    AddReference(i.Type);
                }
            }

            if (item.SeeAlsos != null)
            {
                foreach (var i in item.SeeAlsos)
                {
                    AddReference(i.Type);
                }
            }

            _generator.DefaultVisit(symbol, item, this);
            return(item);
        }
Beispiel #5
0
 private void AddInheritedMembers(INamedTypeSymbol symbol, INamedTypeSymbol type, Dictionary <string, string> dict, IReadOnlyList <string> typeParamterNames)
 {
     foreach (var m in from m in type.GetMembers()
              where !(m is INamedTypeSymbol)
              where VisitorHelper.CanVisit(m, symbol == type || !symbol.IsSealed || symbol.TypeKind != TypeKind.Struct)
              where IsInheritable(m)
              select m)
     {
         var sig = MemberSigRegex.Replace(SpecIdHelper.GetSpecId(m, typeParamterNames), string.Empty);
         if (!dict.ContainsKey(sig))
         {
             dict.Add(sig, type == symbol ? null : AddSpecReference(m, typeParamterNames));
         }
     }
 }
        private ImplementsClauseSyntax GetImplementsClause(IPropertySymbol symbol)
        {
            if (symbol.ExplicitInterfaceImplementations.Length == 0)
            {
                return(null);
            }
            var list = (from eii in symbol.ExplicitInterfaceImplementations
                        where VisitorHelper.CanVisit(eii)
                        select SyntaxFactory.QualifiedName(GetQualifiedNameSyntax(eii.ContainingType), (SimpleNameSyntax)SyntaxFactory.ParseName(eii.Name))).ToList();

            if (list.Count == 0)
            {
                return(null);
            }
            return(SyntaxFactory.ImplementsClause(SyntaxFactory.SeparatedList(list.ToArray())));
        }
 private static string GetEiiContainerTypeName(IPropertySymbol symbol)
 {
     if (symbol.ExplicitInterfaceImplementations.Length == 0)
     {
         return(null);
     }
     for (int i = 0; i < symbol.ExplicitInterfaceImplementations.Length; i++)
     {
         if (VisitorHelper.CanVisit(symbol.ExplicitInterfaceImplementations[i]))
         {
             return(NameVisitorCreator.GetCSharp(NameOptions.UseAlias | NameOptions.WithGenericParameter).GetName(symbol.ExplicitInterfaceImplementations[i].ContainingType));
         }
     }
     Debug.Fail("Should not be here!");
     return(null);
 }
        private static string GetMemberName(IPropertySymbol symbol)
        {
            string name = symbol.Name;

            if (symbol.ExplicitInterfaceImplementations.Length == 0)
            {
                return(symbol.Name);
            }
            for (int i = 0; i < symbol.ExplicitInterfaceImplementations.Length; i++)
            {
                if (VisitorHelper.CanVisit(symbol.ExplicitInterfaceImplementations[i]))
                {
                    return(symbol.ExplicitInterfaceImplementations[i].Name);
                }
            }
            Debug.Fail("Should not be here!");
            return(symbol.Name);
        }