0

I need to document a complex solution for CI/CD and part of it is to build the Unit Test for all projects. My VS Solution Contains 17 projects.

enter image description here

Each of these projects contains at least 10 classes per project and most of the classes are replete with complex methods, some projects have more than a 100 classes. Most of the projects are console applications, but we have an ASP MVC project too.

I'm aware that I need to prioritize the work, but in order to do it effectively, I need to have a full list of methods per class.

Does anyone know any proper technique to do it? I know that reflection could work, but it will be class by class and it might take ages too.

Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76
  • 2
    With reflection you could load all assemblies, get all types and from there all methods. Writing that out should be like 20 lines and not run longer than a few moments. – thehennyy Jul 26 '19 at 14:33
  • Yes, but how can I connect all projects? Or should I write a special console application per project and start getting them? As I said before each project has like 10, 20 up to 100 classes. – Federico Navarrete Jul 26 '19 at 14:34
  • 1
    I would just compile the projects and stuff all assemblies into one folder. Then create a new project that loads all these assemblies from the folder. – thehennyy Jul 26 '19 at 14:35
  • 1
    If you have Visual Studio Enterprise you can use the "Calculate Code Metrics" feature. This is under Analyze -> Calculate Code Metrics -> For Solution – LaCartouche Jul 26 '19 at 14:43

2 Answers2

3

In each Project Properties, in the Build section, enable XML documentation file. Build all your projects, and collect the output XML files from the output folders. This will give you the list of all classes and their methods, argument names/types, etc.

enter image description here

RobertBaron
  • 2,817
  • 1
  • 12
  • 19
3

some time ago I wrote simple console app. this code grab all methods from your .sln automatically:

    static void Main(string[] args)
    {
        var rootPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
        var dlls = Directory.GetFiles(rootPath, "*.dll", SearchOption.AllDirectories).Where(row => row.Contains("\\bin\\")).Distinct();

        foreach (var dll in dlls)
        {
            var assembly = Assembly.LoadFrom(dll);
            var types = assembly.GetTypes();
            foreach (var type in types)
            {
                var members = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Static);
                foreach (MemberInfo member in members)
                {
                    Console.WriteLine($"{assembly.GetName().Name}.{type.Name}.{member.Name}");
                }

                var members2 = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Static);
                foreach (MemberInfo member in members2)
                {
                    Console.WriteLine($"{assembly.GetName().Name}.{type.Name}.{member.Name}");
                }
            }
        }
    }

enter image description here

dlls - all dll files from your solution. types - all your class in dll. members - all methods. I hope this help you.