Exemplo n.º 1
0
 private static void SetHref(SourceDetail s, Dictionary <string, MetadataItem> index, string currentName)
 {
     if (s == null)
     {
         return;
     }
     if (!s.IsExternalPath)
     {
         s.Href = ResolveInternalLink(index, s.Name, currentName);
     }
     else
     {
         // Set ExternalPath to null;
         s.Href = null;
     }
 }
Exemplo n.º 2
0
        public static ApiParameter GetParameterDescription(ISymbol symbol, MetadataItem item, bool isReturn, SymbolDisplayFormat displayFormat)
        {
            SourceDetail id  = null;
            string       raw = item.RawComment;
            // TODO: GetDocumentationCommentXml for parameters seems not accurate
            string name       = symbol.Name;
            var    paraSymbol = symbol as IParameterSymbol;

            if (paraSymbol != null)
            {
                // TODO: why BaseType?
                id = GetLinkDetail(paraSymbol.Type, displayFormat);
            }

            // when would it be type symbol?
            var typeSymbol = symbol as ITypeSymbol;

            if (typeSymbol != null)
            {
                Debug.Assert(typeSymbol != null, "Should be TypeSymbol");

                // TODO: check what name is
                // name = DescriptionConstants.ReturnName;
                id = GetLinkDetail(typeSymbol, displayFormat);
            }

            var propertySymbol = symbol as IPropertySymbol;

            if (propertySymbol != null)
            {
                // TODO: check what name is
                // name = DescriptionConstants.ReturnName;
                id = GetLinkDetail(propertySymbol.Type, displayFormat);
            }

            string comment = isReturn ? TripleSlashCommentParser.GetReturns(raw, true) :
                             TripleSlashCommentParser.GetParam(raw, name, true);

            return(new ApiParameter()
            {
                Name = name, Type = id, Description = comment
            });
        }
Exemplo n.º 3
0
        public static SourceDetail GetSourceDetail(ISymbol symbol)
        {
            if (symbol == null)
            {
                return(null);
            }

            var syntaxRef = symbol.DeclaringSyntaxReferences.LastOrDefault();

            if (symbol.IsExtern || syntaxRef == null)
            {
                return(new SourceDetail {
                    IsExternalPath = true, Path = symbol.ContainingAssembly?.Name
                });
            }

            var syntaxNode = syntaxRef.GetSyntax();

            Debug.Assert(syntaxNode != null);
            if (syntaxNode != null)
            {
                var source = new SourceDetail
                {
                    StartLine = syntaxNode.SyntaxTree.GetLineSpan(syntaxNode.Span).StartLinePosition.Line,
                    Path      = syntaxNode.SyntaxTree.FilePath,
                };

                source.Remote = GitUtility.GetGitDetail(source.Path);
                if (source.Remote != null)
                {
                    source.Path = source.Path.FormatPath(UriKind.Relative, source.Remote.LocalWorkingDirectory);
                }
                return(source);
            }

            return(null);
        }
        public override MetadataItem VisitNamedType(INamedTypeSymbol symbol)
        {
            var item = this.DefaultVisit(symbol);

            if (item == null)
            {
                return(null);
            }

            var syntaxRef = symbol.DeclaringSyntaxReferences.FirstOrDefault();

            Debug.Assert(syntaxRef != null);
            if (syntaxRef == null)
            {
                return(null);
            }
            var syntaxNode = syntaxRef.GetSyntax();

            Debug.Assert(syntaxNode != null);
            if (syntaxNode == null)
            {
                return(null);
            }

            var type = symbol.BaseType;

            if (type != null)
            {
                item.Inheritance = new List <SourceDetail>();
                while (type != null)
                {
                    SourceDetail link = VisitorHelper.GetLinkDetail(type, ShortDisplayFormat);

                    item.Inheritance.Add(link);
                    type = type.BaseType;
                }

                item.Inheritance.Reverse();
            }
            Debug.Assert(this.parent != null && this.currentNamespace != null);
            if (this.currentNamespace != null)
            {
                if (this.currentNamespace.Items == null)
                {
                    this.currentNamespace.Items = new List <MetadataItem>();
                }

                this.currentNamespace.Items.Add(item);
            }

            item.Type = VisitorHelper.GetMemberTypeFromTypeKind(symbol.TypeKind);
            string syntaxStr = this.GetSyntaxContent(item.Type, symbol, syntaxNode);

            Debug.Assert(!string.IsNullOrEmpty(syntaxStr));
            if (string.IsNullOrEmpty(syntaxStr))
            {
                return(null);
            }

            if (item.Syntax == null)
            {
                item.Syntax = new SyntaxDetail {
                    Content = new Dictionary <SyntaxLanguage, string>()
                };
            }

            if (item.Syntax.Content == null)
            {
                item.Syntax.Content = new Dictionary <SyntaxLanguage, string>();
            }

            item.Syntax.Content.Add(this.language, syntaxStr);

            var parentSaved = this.parent;

            this.parent = item;

            foreach (var member in symbol.GetMembers())
            {
                var nsItem = member.Accept(this);
            }

            this.parent = parentSaved;
            return(item);
        }