You don't need to store the type name and then use typeof
. You already have the type:-
var appServiceClassTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(x => x.IsClass && x.Namespace == ...)
.ToList();
var appServiceClasses = appServiceClassTypes.Select(x => x.Name);
var methodNames = appServiceClassTypes.SelectMany(x => x.GetMethods())
.Select(x => x.Name)
.ToList();
If you don't actually need the appServiceClasses
collection anywhere, you should just be able to chain those together:-
var methodNames = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(x => x.IsClass && x.Namespace == ...)
.SelectMany(x => x.GetMethods())
.Select(x => x.Name)
.ToList();
You probably want to know which methods belong to which class, though:-
var methods = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(x => x.IsClass && x.Namespace == ...)
.Select(x => new Tuple<string, IEnumerable<string>>(
x.Name,
x.GetMethods().Select(y => y.Name)));
or:-
var methods = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(x => x.IsClass && x.Namespace == ...)
.ToDictionary(
x => x.Name,
x => x.GetMethods().Select(y => y.Name));