Пример для
русалки:
namespace ConsoleAppTest
{
internal static class Program
{
#region Public Methods
public static IEnumerable<Type> GetInheritanceHierarchy(this Type type)
{
for (var current = type; current != null; current = current.BaseType)
yield return current;
}
#endregion Public Methods
#region Private Methods
private static void Main(string[] args)
{
IEnumerable<Type>? l1 = typeof(object).GetInheritanceHierarchy();
IEnumerable<Type>? nsTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(t => t.GetTypes())
.Where(t => t.IsClass);
uint idIndex = 0;
Dictionary<Type, uint> map = [];
List<string> hierarchy = [];
foreach (Type type in nsTypes)
{
IEnumerable<Type> iTypes = type.GetInheritanceHierarchy().Reverse();
if (iTypes is not null && iTypes.Any())
{
IEnumerable<string> hierachyNodes = iTypes.Select(t => $"T{GetTypeId(t)}");
hierarchy.Add(string.Join(" --> ", hierachyNodes));
}
else
{
hierarchy.Add($"T{GetTypeId(type)}");
}
}
IEnumerable<string> nodes = map.Select(p => $"T{p.Value}(\"{p.Key}\")");
string allNodes = string.Join("\n ", nodes);
string allhierarchy = string.Join("\n ", hierarchy);
string mermaidChart = $"flowchart TD\n\n%% Nodes\n {allNodes}\n\n%% Hierarchy\n {allhierarchy}";
File.WriteAllText("mermaid chart.txt", mermaidChart);
Console.WriteLine($"Done. Classes processed: {nodes.Count()}");
Console.ReadKey();
uint GetTypeId(Type type)
{
if (map.TryGetValue(type, out uint id))
{
return id;
}
map[type] = idIndex;
return idIndex++;
}
}
#endregion Private Methods
}
}
Русалка умеет в PNG, SVG и другие форматы.