示例#1
0
        public NamespaceViewModel(IReadOnlyList<DocumentedNamespace> namespaces)
        {
            if (namespaces.Count == 0)
            {
                throw new ArgumentException("No namespaces in list.");
            }

            _data = namespaces[0];
            _name = _data.Name;

            var namespaceWithSummary = namespaces.FirstOrDefault(x => x.Summary != null);
            if (namespaceWithSummary != null)
            {
                _summary = namespaceWithSummary.Summary;
            }

            _classes = new List<DocumentedType>();
            _interfaces = new List<DocumentedType>();
            foreach (var @namespace in namespaces)
            {
                var classes = @namespace.Types.Where(x => x.Definition.IsClass && !IsExtensionMethodClass(x)).ToArray();
                _classes.AddRange(classes);

                var interfaces = @namespace.Types.Where(x => x.Definition.IsInterface).ToArray();
                _interfaces.AddRange(interfaces);
            }

            // For child namespaces, just get them from the first one
            // since they're going to be the same anyway.
            _namespaces = new List<DocumentedNamespace>();
            foreach (var childNamespace in _data.Tree.Children)
            {
                _namespaces.Add(childNamespace.Namespace);
            }
        }
示例#2
0
 public static IHtmlString BreadCrumb(this ApiServices context, DocumentedNamespace @namespace)
 {
     var breadcrumb = new Breadcrumb();
     breadcrumb.AppendApiRoot();
     breadcrumb.AppendNamespaces(context, @namespace, false);
     return breadcrumb.Render();
 }
示例#3
0
        public static void AppendNamespacesOld(this IBreadcrumbItem breadcrumb, ApiServices context, DocumentedNamespace @namespace, bool link)
        {
            var owner = CreateNamespace(context, @namespace, link);
            var dropdown = new BreadcrumbDropdown(owner);
            var parts = @namespace.Identity.Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
            for (int index = 0; index < parts.Length - 1; index++)
            {
                var temp = string.Join(".", parts.Take(index + 1));
                var documentedNamespace = context.ModelResolver.FindNamespace(temp);
                if (documentedNamespace != null)
                {
                    dropdown.AppendNamespace(context, documentedNamespace, true);
                }
            }
            if (link)
            {
                dropdown.Append(owner);
            }

            if (dropdown.Count > 1)
            {
                breadcrumb.Append(dropdown);
            }
            else
            {
                breadcrumb.Append(owner);
            }
        }
示例#4
0
 public static IHtmlString NamespaceName(this ApiServices context, DocumentedNamespace @namespace)
 {
     if (@namespace != null)
     {
         return MvcHtmlString.Create(@namespace.Name);
     }
     return MvcHtmlString.Create(string.Empty);
 }
示例#5
0
 public TypeViewModel(DocumentedType data)
 {
     _data = data;
     _namespace = data.Namespace;
     _constructors = new List<DocumentedMethod>(data.Constructors);
     _methods = new List<DocumentedMethod>(data.Methods);
     _extensionMethods = new List<DocumentedMethod>(data.ExtensionMethods);
     _operators = new List<DocumentedMethod>(data.Operators);
     _properties = new List<DocumentedProperty>(GetProperties(data));
     _fields = new List<DocumentedField>(data.Fields);
 }
示例#6
0
 public static IHtmlString NamespaceUrl(this ApiServices context, DocumentedNamespace @namespace)
 {
     if (@namespace != null)
     {
         var url = context.UrlResolver.GetUrl(@namespace.Identity);
         if (url != null)
         {
             return MvcHtmlString.Create(url);
         }
     }
     return MvcHtmlString.Create(string.Empty);
 }
示例#7
0
 public static IHtmlString NamespaceLink(this ApiServices context, DocumentedNamespace @namespace)
 {
     if (@namespace != null)
     {
         var url = context.UrlResolver.GetUrl(@namespace.Identity);
         if (url != null)
         {
             var writer = new HtmlTextWriter(new StringWriter());
             writer.AddAttribute(HtmlTextWriterAttribute.Href, url);
             writer.RenderBeginTag(HtmlTextWriterTag.A);
             writer.WriteEncodedText(@namespace.Name);
             writer.RenderEndTag();
             return MvcHtmlString.Create(writer.InnerWriter.ToString());
         }
         return MvcHtmlString.Create(@namespace.Name);
     }
     return MvcHtmlString.Create(string.Empty);
 }
示例#8
0
 private string GetUrl(DocumentedNamespace ns)
 {
     return _service.GetRoutePart(ns);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DocumentedNamespaceTree"/> class.
 /// </summary>
 /// <param name="namespace">The namespace.</param>
 public DocumentedNamespaceTree(DocumentedNamespace @namespace)
 {
     _namespace = @namespace;
     _children  = new List <DocumentedNamespaceTree>();
 }
示例#10
0
        private static DocumentedAssembly MapAssembly(IAssemblyInfo assembly, XmlDocumentationModel model)
        {
            var types = new List<DocumentedType>();

            // Iterate all types in assembly.
            foreach (var type in assembly.Types)
            {
                var documentedType = MapType(type, model);
                types.Add(documentedType);

                // Add a reference to the type for every constructor.
                foreach (var constructor in documentedType.Constructors)
                {
                    constructor.Type = documentedType;
                }

                // Add a reference to the type for every method.
                foreach (var method in documentedType.Methods)
                {
                    method.Type = documentedType;
                }

                // Add a reference to the type for every method.
                foreach (var @operator in documentedType.Operators)
                {
                    @operator.Type = documentedType;
                }

                // Add a reference to the type for every property.
                foreach (var property in documentedType.Properties)
                {
                    property.Type = documentedType;
                }

                // Add a reference to the type for every method.
                foreach (var field in documentedType.Fields)
                {
                    field.Type = documentedType;
                }
            }

            // Now group all the types in this assembly by their namespace.
            var namespaces = new List<DocumentedNamespace>();
            var namespaceGroups = types.GroupBy(x => x.Definition.Namespace);
            foreach (var namespaceGroup in namespaceGroups)
            {
                var namespaceTypes = namespaceGroup.ToList();

                // Do we have a documentation for this namespace?
                var documentation = namespaceGroup.FirstOrDefault(x => x.Definition.Name.EndsWith("NamespaceDoc"));
                var summary = documentation != null ? documentation.Summary : null;
                if (documentation != null)
                {
                    namespaceTypes.Remove(documentation);
                }

                // Create a namespace for each grouping.
                var @namespace = new DocumentedNamespace(namespaceGroup.Key, namespaceGroup.Key, namespaceTypes, summary, assembly.Metadata);
                namespaces.Add(@namespace);

                // Connect the types in this namespace to the namespace.
                foreach (var documentedType in namespaceGroup)
                {
                    documentedType.Namespace = @namespace;
                }
            }

            // Create an documented assembly out of it.
            var documentedAssembly = new DocumentedAssembly(assembly, namespaces, assembly.Metadata);

            // Add the documented assembly as a parent of all namespaces.
            foreach (var @namespace in namespaces)
            {
                @namespace.Assembly = documentedAssembly;
            }

            // Return the documented assembly.
            return documentedAssembly;
        }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DocumentedNamespaceTree"/> class.
 /// </summary>
 /// <param name="namespace">The namespace.</param>
 public DocumentedNamespaceTree(DocumentedNamespace @namespace)
 {
     _namespace = @namespace;
     _children = new List<DocumentedNamespaceTree>();
 }
示例#12
0
        private static DocumentedAssembly MapAssembly(IAssemblyInfo assembly, XmlDocumentationModel model)
        {
            var types = new List <DocumentedType>();

            // Iterate all types in assembly.
            foreach (var type in assembly.Types)
            {
                var documentedType = MapType(type, model);
                types.Add(documentedType);

                // Add a reference to the type for every constructor.
                foreach (var constructor in documentedType.Constructors)
                {
                    constructor.Type = documentedType;
                }

                // Add a reference to the type for every method.
                foreach (var method in documentedType.Methods)
                {
                    method.Type = documentedType;
                }

                // Add a reference to the type for every method.
                foreach (var @operator in documentedType.Operators)
                {
                    @operator.Type = documentedType;
                }

                // Add a reference to the type for every property.
                foreach (var property in documentedType.Properties)
                {
                    property.Type = documentedType;
                }

                // Add a reference to the type for every method.
                foreach (var field in documentedType.Fields)
                {
                    field.Type = documentedType;
                }
            }

            // Now group all the types in this assembly by their namespace.
            var namespaces      = new List <DocumentedNamespace>();
            var namespaceGroups = types.GroupBy(x => x.Definition.Namespace);

            foreach (var namespaceGroup in namespaceGroups)
            {
                var namespaceTypes = namespaceGroup.ToList();

                // Do we have a documentation for this namespace?
                var documentation = namespaceGroup.FirstOrDefault(x => x.Definition.Name.EndsWith("NamespaceDoc"));
                var summary       = documentation?.Summary;
                if (documentation != null)
                {
                    namespaceTypes.Remove(documentation);
                }

                // Create a namespace for each grouping.
                var @namespace = new DocumentedNamespace(namespaceGroup.Key, namespaceGroup.Key, namespaceTypes, summary, assembly.Metadata);
                namespaces.Add(@namespace);

                // Connect the types in this namespace to the namespace.
                foreach (var documentedType in namespaceGroup)
                {
                    documentedType.Namespace = @namespace;
                }
            }

            // Create an documented assembly out of it.
            var documentedAssembly = new DocumentedAssembly(assembly, namespaces, assembly.Metadata);

            // Add the documented assembly as a parent of all namespaces.
            foreach (var @namespace in namespaces)
            {
                @namespace.Assembly = documentedAssembly;
            }

            // Return the documented assembly.
            return(documentedAssembly);
        }
示例#13
0
 public string GetRoutePart(DocumentedNamespace @namespace)
 {
     return @namespace.Identity.ToLowerInvariant();
 }
示例#14
0
        public static void AppendNamespaces(this IBreadcrumbItem breadcrumb, ApiServices context, DocumentedNamespace @namespace, bool link)
        {
            var current = CreateNamespace(context, @namespace, link);

            var parentNamespaces = new List<DocumentedNamespace>();
            var parent = @namespace.Tree.Parent;
            while (parent != null)
            {
                parentNamespaces.Add(parent.Namespace);
                parent = parent.Parent;
            }

            if (!link)
            {
                if (parentNamespaces.Count == 1)
                {
                    // Add the item in the drop down as an item.
                    breadcrumb.AppendNamespace(context, parentNamespaces[0], true);
                    // Append the current namespace.
                    breadcrumb.Append(current);
                }
                else if(parentNamespaces.Count > 1)
                {
                    // Create a dropdown with the first parent namespace as the owner.
                    var dropdown = new BreadcrumbDropdown(CreateNamespace(context, parentNamespaces[0], true));
                    foreach (var parentNamespace in parentNamespaces)
                    {
                        dropdown.AppendNamespace(context, parentNamespace, true);
                    }
                    // Append the dropdown.
                    breadcrumb.Append(dropdown);
                    // Append the current namespace.
                    breadcrumb.Append(current);
                }
                else
                {
                    // No parents. Just show the current namespace.
                    breadcrumb.Append(current);
                }
            }
            else
            {
                if (parentNamespaces.Count >= 1)
                {
                    // Create a dropdown with the current namespace as the owner.
                    var dropdown = new BreadcrumbDropdown(current);
                    dropdown.Append(current);
                    foreach (var parentNamespace in parentNamespaces)
                    {
                        dropdown.AppendNamespace(context, parentNamespace, true);
                    }
                    // Append the dropdown.
                    breadcrumb.Append(dropdown);
                }
                else
                {
                    // No parents. Just show the current namespace.
                    breadcrumb.Append(current);
                }
            }
        }
示例#15
0
 private static BreadcrumbItem CreateNamespace(ApiServices context, DocumentedNamespace @namespace, bool link)
 {
     Uri uri = null;
     if (link)
     {
         uri = new Uri(context.UrlResolver.GetUrl(@namespace.Identity), UriKind.Relative);
     }
     return new BreadcrumbItem(MvcHtmlString.Create(@namespace.Name), uri);
 }
示例#16
0
 public static void AppendNamespace(this IBreadcrumbItem breadcrumb, ApiServices context, DocumentedNamespace @namespace, bool link)
 {
     breadcrumb.Append(CreateNamespace(context, @namespace, link));
 }