Задать вопрос
@SmeliyR

Есть в графическом виде дерево иерархии классов .net?

Есть в графическом виде дерево классов .net framework ? Желательно для версии 2.0 но можно и более поздней. То есть не просто перечисление классов а именно их иерархия, какой класс от какого произошёл чтоб было
нарисовано
4d94352431386f5948c78221f512309b.jpg
  • Вопрос задан
  • 103 просмотра
Подписаться 1 Простой 1 комментарий
Пригласить эксперта
Ответы на вопрос 2
Lord_of_Rings
@Lord_of_Rings
Дунадан - северный странник. Злой, но очень добрый
Нет
Ответ написан
Комментировать
VoidVolker
@VoidVolker
Dark side eye. А у нас печеньки! А у вас?
Пример для русалки:
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>? nsTypes = AppDomain.CurrentDomain.GetAssemblies()
                       .SelectMany(t => t.GetTypes())
                       .Where(t => t.IsClass);

            uint idIndex = 0;
            Dictionary<Type, uint> map = [];
            List<List<Type>> hierarchy = [];

            foreach (Type type in nsTypes)
            {
                IEnumerable<Type> iTypes = type.GetInheritanceHierarchy().Reverse();
                if (iTypes is not null && iTypes.Any())
                {
                    hierarchy.Add(iTypes.ToList());
                }
                else
                {
                    hierarchy.Add([type]);
                }
            }

            // Process hierarchy first to get nodes id's
            string allhierarchy = string.Join(
                "\n  ",
                hierarchy.Select(types =>
                    string.Join(
                        " --> ",
                        types.Select(t => $"T{GetTypeId(t)}")
                    )
                )
            );

            // Now process all nodes names
            IEnumerable<string> nodes = map.Select(p => $"T{p.Value}(\"{p.Key}\")");
            string allNodes = string.Join("\n  ", nodes);

            // Combine all data to chart
            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 и другие форматы.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы