コード例 #1
0
 /// <summary>
 /// Adds the specified namespace to the namespace's namespace list.
 /// </summary>
 internal void AddNamespace(NamespaceDocumentation namespaceDocumentation) =>
 m_Namespaces.Add(namespaceDocumentation.NamespaceId, namespaceDocumentation);
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="TypeDocumentation"/>.
        /// </summary>
        /// <param name="assemblyDocumentation">The documentation model of the assembly that defines the type.</param>
        /// <param name="namespaceDocumentation">The documentation model of the type's namespace.</param>
        /// <param name="definition">The type's underlying Mono.Cecil definition.</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        /// <param name="logger">The logger to use.</param>
        internal TypeDocumentation(AssemblyDocumentation assemblyDocumentation,
                                   NamespaceDocumentation namespaceDocumentation,
                                   TypeDefinition definition,
                                   IXmlDocsProvider xmlDocsProvider,
                                   ILogger logger,
                                   TypeDocumentation?declaringType)
        {
            TypeId        = definition.ToTypeId();
            DeclaringType = declaringType;

            AssemblyDocumentation  = assemblyDocumentation ?? throw new ArgumentNullException(nameof(assemblyDocumentation));
            NamespaceDocumentation = namespaceDocumentation ?? throw new ArgumentNullException(nameof(namespaceDocumentation));
            Definition             = definition ?? throw new ArgumentNullException(nameof(definition));
            m_XmlDocsProvider      = xmlDocsProvider ?? throw new ArgumentNullException(nameof(xmlDocsProvider));
            m_Logger = logger ?? throw new ArgumentNullException(nameof(logger));

            m_Logger.LogDebug($"Loading documentation for type '{definition.FullName}'");

            Kind = definition.Kind();

            m_Logger.LogDebug("Loading fields");
            m_Fields = definition.Fields
                       .Where(field => field.IsPublic && !field.Attributes.HasFlag(FieldAttributes.SpecialName))
                       .Select(field => new FieldDocumentation(this, field, xmlDocsProvider))
                       .ToDictionary(f => f.MemberId);

            Fields = ReadOnlyCollectionAdapter.Create(m_Fields.Values);

            m_Logger.LogDebug("Loading events");
            m_Events = definition.Events
                       .Where(ev => (ev.AddMethod?.IsPublic == true || ev.RemoveMethod?.IsPublic == true))
                       .Select(e => new EventDocumentation(this, e, xmlDocsProvider))
                       .ToDictionary(e => e.MemberId);

            Events = ReadOnlyCollectionAdapter.Create(m_Events.Values);

            m_Logger.LogDebug("Loading properties");
            m_Properties = definition.Properties
                           .Where(property => (property.GetMethod?.IsPublic == true || property.SetMethod?.IsPublic == true) && !property.HasParameters)
                           .Select(p => new PropertyDocumentation(this, p, xmlDocsProvider))
                           .ToDictionary(p => p.MemberId);

            Properties = ReadOnlyCollectionAdapter.Create(m_Properties.Values);

            m_Logger.LogDebug("Loading indexers");
            m_Indexers = definition.Properties
                         .Where(property => (property.GetMethod?.IsPublic == true || property.SetMethod?.IsPublic == true) && property.HasParameters)
                         .GroupBy(p => p.Name)
                         .Select(group => new IndexerDocumentation(this, group, xmlDocsProvider))
                         .ToDictionary(indexer => indexer.Name);

            Indexers = ReadOnlyCollectionAdapter.Create(m_Indexers.Values);

            m_Logger.LogDebug("Loading constructors");
            var ctors = definition.GetPublicConstrutors();

            if (ctors.Any())
            {
                Constructors = new ConstructorDocumentation(this, ctors, xmlDocsProvider);
            }

            m_Logger.LogDebug("Loading methods");
            m_Methods = definition.GetPublicMethods()
                        .Where(m => !m.IsOperator())
                        .GroupBy(x => x.Name)
                        .Select(group => new MethodDocumentation(this, group, xmlDocsProvider))
                        .ToDictionary(m => m.Name);

            Methods = ReadOnlyCollectionAdapter.Create(m_Methods.Values);

            m_Logger.LogDebug("Loading operator overloads");
            m_Operators = definition.GetPublicMethods()
                          .GroupBy(x => x.GetOperatorKind())
                          .Where(group => group.Key.HasValue)
                          .Select(group => new OperatorDocumentation(this, group, xmlDocsProvider))
                          .ToDictionary(x => x.Kind);


            Operators = ReadOnlyCollectionAdapter.Create(m_Operators.Values);

            m_Logger.LogDebug("Loading inheritance hierarchy.");
            InheritanceHierarchy = LoadInheritanceHierarchy();

            m_Logger.LogDebug("Loading custom attributes");
            Attributes = Definition
                         .GetCustomAttributes()
                         .Select(x => x.AttributeType.ToTypeId())
                         .ToArray();

            m_Logger.LogDebug("Loading implemented interfaces");
            ImplementedInterfaces = LoadImplementedInterfaces();

            TypeParameters = LoadTypeParameters();

            var documentationComments = m_XmlDocsProvider.TryGetDocumentationComments(MemberId);

            Summary = documentationComments?.Summary ?? TextBlock.Empty;
            Remarks = documentationComments?.Remarks ?? TextBlock.Empty;
            SeeAlso = documentationComments?.SeeAlso?.AsReadOnlyList() ?? Array.Empty <SeeAlsoElement>();
            Example = documentationComments?.Example ?? TextBlock.Empty;

            CSharpDefinition = CSharpDefinitionFormatter.GetDefinition(definition);

            IsObsolete      = definition.IsObsolete(out var obsoleteMessage);
            ObsoleteMessage = obsoleteMessage;
        }