/// <inheritdoc /> public IDocumentation?TryGetDocumentation(MemberId id) { switch (id) { case TypeId typeId when typeId.Equals(TypeId): return(this); case FieldId fieldId when fieldId.DefiningType.Equals(TypeId): return(m_Fields.GetValueOrDefault(fieldId)); case EventId eventId when eventId.DefiningType.Equals(TypeId): return(m_Events.GetValueOrDefault(eventId)); case PropertyId propertyId when propertyId.DefiningType.Equals(TypeId) && propertyId.Parameters.Count == 0: return(m_Properties.GetValueOrDefault(propertyId)); case PropertyId propertyId when propertyId.DefiningType.Equals(TypeId) && propertyId.Parameters.Count > 0: return(m_Indexers.GetValueOrDefault(propertyId.Name)); case MethodId methodId when methodId.DefiningType.Equals(TypeId): if (methodId.IsConstructor()) { return(Constructors !.TryGetDocumentation(methodId)); } if (m_Methods.ContainsKey(methodId.Name)) { return(m_Methods[methodId.Name].TryGetDocumentation(methodId)); } var operatorKind = methodId.GetOperatorKind(); if (operatorKind.HasValue && m_Operators.ContainsKey(operatorKind.Value)) { return(m_Operators[operatorKind.Value].TryGetDocumentation(methodId)); } return(null); default: return(AssemblyDocumentation.TryGetDocumentation(id)); } }
/// <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; }