Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="TypeParameterDocumentation"/>.
        /// </summary>
        /// <param name="parent">The parent documentation model (the type of method that defines the type parameter).</param>
        /// <param name="parentId">The if of the parent documentation model (the type of method that defines the type parameter).</param>
        /// <param name="definition">The underlying Mono.Cecil definition of the type parameter.</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        internal TypeParameterDocumentation(IAssemblyMemberDocumentation parent, MemberId parentId, GenericParameter definition, IXmlDocsProvider xmlDocsProvider)
        {
            m_Parent        = parent;
            parentId        = parentId ?? throw new ArgumentNullException(nameof(parentId));
            Definition      = definition;
            xmlDocsProvider = xmlDocsProvider ?? throw new ArgumentNullException(nameof(xmlDocsProvider));

            Description = xmlDocsProvider.TryGetDocumentationComments(parentId)?.TypeParameters?.GetValueOrDefault(definition.Name);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of <see cref="ParameterDocumentation"/>.
        /// </summary>
        /// <param name="overloadDocumentation">The overload that defines the parameter.</param>
        /// <param name="definition">The underlying Mono.Cecil definition of the parameter.</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        internal ParameterDocumentation(OverloadDocumentation overloadDocumentation, ParameterDefinition definition, IXmlDocsProvider xmlDocsProvider)
        {
            OverloadDocumentation = overloadDocumentation ?? throw new ArgumentNullException(nameof(overloadDocumentation));
            xmlDocsProvider       = xmlDocsProvider ?? throw new ArgumentNullException(nameof(xmlDocsProvider));
            Definition            = definition ?? throw new ArgumentNullException(nameof(definition));

            ParameterType = definition.ParameterType.ToTypeId();

            Description = xmlDocsProvider.TryGetDocumentationComments(overloadDocumentation.MemberId)?.Parameters?.GetValueOrDefault(definition.Name);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of <see cref="FieldDocumentation"/>.
        /// </summary>
        /// <param name="typeDocumentation">The documentation model of the type defining the field.</param>
        /// <param name="definition">The underlying Mono.Cecil definition of the field.</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        /// <exception cref="ArgumentNullException">Thrown when one of the constructor arguments is null.</exception>
        internal FieldDocumentation(TypeDocumentation typeDocumentation, FieldDefinition definition, IXmlDocsProvider xmlDocsProvider)
            : base(typeDocumentation, definition.ToMemberId(), xmlDocsProvider, definition)
        {
            Definition      = definition ?? throw new ArgumentNullException(nameof(definition));
            xmlDocsProvider = xmlDocsProvider ?? throw new ArgumentNullException(nameof(xmlDocsProvider));

            Type             = definition.FieldType.ToTypeId();
            CSharpDefinition = CSharpDefinitionFormatter.GetDefinition(definition);

            Value = xmlDocsProvider.TryGetDocumentationComments(MemberId)?.Value ?? TextBlock.Empty;
        }
Esempio n. 4
0
        // private protected constructor => prevent implementation outside of this assembly
        private protected OverloadDocumentation(MemberId memberId, IXmlDocsProvider xmlDocsProvider)
        {
            MemberId = memberId ?? throw new ArgumentNullException(nameof(memberId));

            var documentationComments = xmlDocsProvider.TryGetDocumentationComments(memberId);

            Summary    = documentationComments?.Summary ?? TextBlock.Empty;
            Remarks    = documentationComments?.Remarks ?? TextBlock.Empty;
            SeeAlso    = documentationComments?.SeeAlso?.AsReadOnlyList() ?? Array.Empty <SeeAlsoElement>();
            Returns    = documentationComments?.Returns ?? TextBlock.Empty;
            Exceptions = documentationComments?.Exceptions?.AsReadOnlyList() ?? Array.Empty <ExceptionElement>();
            Example    = documentationComments?.Example ?? TextBlock.Empty;
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of <see cref="PropertyDocumentation"/>.
        /// </summary>
        /// <param name="typeDocumentation">The documentation model of the type defining the property.</param>
        /// <param name="definition">The underlying Mono.Cecil definition of the property.</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        internal PropertyDocumentation(TypeDocumentation typeDocumentation, PropertyDefinition definition, IXmlDocsProvider xmlDocsProvider)
            : base(typeDocumentation, definition.ToMemberId(), xmlDocsProvider, definition)
        {
            Definition      = definition ?? throw new ArgumentNullException(nameof(definition));
            xmlDocsProvider = xmlDocsProvider ?? throw new ArgumentNullException(nameof(xmlDocsProvider));

            Type             = definition.PropertyType.ToTypeId();
            CSharpDefinition = CSharpDefinitionFormatter.GetDefinition(definition);

            var documentationComments = xmlDocsProvider?.TryGetDocumentationComments(MemberId);

            Value      = documentationComments?.Value;
            Exceptions = documentationComments?.Exceptions?.AsReadOnlyList() ?? Array.Empty <ExceptionElement>();
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of <see cref="IndexerOverloadDocumentation"/>
        /// </summary>
        /// <param name="indexerDocumentation">The documentation model of the indexer being overloaded.</param>
        /// <param name="definition">The underlying Mono.Cecil definition of the indexer.</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        internal IndexerOverloadDocumentation(
            IndexerDocumentation indexerDocumentation,
            PropertyDefinition definition,
            IXmlDocsProvider xmlDocsProvider) : base(definition.ToMemberId(), xmlDocsProvider)
        {
            IndexerDocumentation = indexerDocumentation ?? throw new ArgumentNullException(nameof(indexerDocumentation));
            Definition           = definition ?? throw new ArgumentNullException(nameof(definition));
            xmlDocsProvider      = xmlDocsProvider ?? throw new ArgumentNullException(nameof(xmlDocsProvider));

            Parameters = definition.HasParameters
                ? definition.Parameters.Select(p => new ParameterDocumentation(this, p, xmlDocsProvider)).ToArray()
                : Array.Empty <ParameterDocumentation>();

            Type             = definition.PropertyType.ToTypeId();
            Signature        = SignatureFormatter.GetSignature(definition);
            CSharpDefinition = CSharpDefinitionFormatter.GetDefinition(definition);
            Value            = xmlDocsProvider.TryGetDocumentationComments(MemberId)?.Value;

            IsObsolete      = definition.IsObsolete(out var obsoleteMessage);
            ObsoleteMessage = obsoleteMessage;
        }
Esempio n. 7
0
        // private protected constructor => prevent implementation outside of this assembly
        private protected SimpleMemberDocumentation(TypeDocumentation typeDocumentation,
                                                    MemberId memberId,
                                                    IXmlDocsProvider xmlDocsProvider,
                                                    ICustomAttributeProvider definitionAttributes) : base(typeDocumentation)
        {
            if (xmlDocsProvider == null)
            {
                throw new ArgumentNullException(nameof(xmlDocsProvider));
            }

            MemberId             = memberId ?? throw new ArgumentNullException(nameof(memberId));
            definitionAttributes = definitionAttributes ?? throw new ArgumentNullException(nameof(definitionAttributes));

            var documentationComments = 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;

            IsObsolete      = definitionAttributes.IsObsolete(out var obsoleteMessage);
            ObsoleteMessage = obsoleteMessage;
        }
Esempio n. 8
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;
        }