// Copyright (c) 2024 Holger Schmidt // // Permission is hereby granted, free of charge, to any person obtaining a copy of this // software and associated documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons // to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or // substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. using System.Collections.Generic; using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.ILSpyX.MermaidDiagrammer { /// Contains type info and metadata for generating a HTML class diagrammer from a source assembly. /// Serialized into JSON by . public sealed class ClassDiagrammer { internal const string NewLine = "\n"; internal string SourceAssemblyName { get; set; } = null!; internal string SourceAssemblyVersion { get; set; } = null!; /// Types selectable in the diagrammer, grouped by their /// to facilitate a structured type selection. internal Dictionary TypesByNamespace { get; set; } = null!; /// Types not included in the , /// but referenced by s that are. /// Contains display names (values; similar to ) /// by their referenced IDs (keys; similar to ). internal Dictionary OutsideReferences { get; set; } = null!; /// Types excluded from the ; /// used to support . internal string[] Excluded { get; set; } = null!; /// A -like structure with collections /// of property relations to one or many other s. public abstract class Relationships { /// Relations to zero or one other instances of s included in the , /// with the display member names as keys and the related as values. /// This is because member names must be unique within the owning , /// while the related may be the same for multiple properties. public Dictionary? HasOne { get; set; } /// Relations to zero to infinite other instances of s included in the , /// with the display member names as keys and the related as values. /// This is because member names must be unique within the owning , /// while the related may be the same for multiple properties. public Dictionary? HasMany { get; set; } } /// The mermaid class diagram definition, inheritance and relationships metadata /// and XML documentation for a from the source assembly. public sealed class Type : Relationships { /// Uniquely identifies the in the scope of the source assembly /// as well as any HTML diagrammer generated from it. /// Should match \w+ to be safe to use as select option value and /// part of the DOM id of the SVG node rendered for this type. /// May be the type name itself. internal string Id { get; set; } = null!; /// The human-readable label for the type, if different from . /// Not guaranteed to be unique in the scope of the . public string? Name { get; set; } /// Contains the definition of the type and its own (not inherited) flat members /// in mermaid class diagram syntax, see https://mermaid.js.org/syntax/classDiagram.html . public string Body { get; set; } = null!; /// The base type directly implemented by this type, with the as key /// and the (optional) differing display name as value of the single entry /// - or null if the base type is . /// Yes, Christopher Lambert, there can only be one. For now. /// But using the same interface as for is convenient /// and who knows - at some point the .Net bus may roll up with multi-inheritance. /// Then this'll look visionary! public Dictionary? BaseType { get; set; } /// Interfaces directly implemented by this type, with their as keys /// and their (optional) differing display names as values. public Dictionary? Interfaces { get; set; } /// Contains inherited members by the of their /// for the consumer to choose which of them to display in an inheritance scenario. public IDictionary? Inherited { get; set; } /// Contains the XML documentation comments for this type /// (using a key) and its members, if available. public IDictionary? XmlDocs { get; set; } /// Members inherited from an ancestor type specified by the Key of . public class InheritedMembers : Relationships { /// The simple, non-complex members inherited from another /// in mermaid class diagram syntax. public string? FlatMembers { get; set; } } } } }