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.
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.
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}");
}
}
}
}
dlls - all dll files from your solution. types - all your class in dll. members - all methods. I hope this help you.