c# - How to find namespace of class by its name using reflection in .net core? -


i have list of string classes names. need create instances of them using activator, of them can in diffrent namespaces. classes can move namespace in future can't hardcode it.

if know you'll never have multiple types same name residing in different namespaces, can iterate on types in assembly , filter on type name. example, works:

var typenames = new[] { "string", "object", "int32" };  var types =  typeof(object).gettypeinfo().assembly     .gettypes()     .where(type => typenames.contains(type.name))     .toarray(); // type[] containing system.string, system.object , system.int32 

this won't break if have multiple types same name, you'll of them in list.


Comments

Popular posts from this blog

How to start daemon on android by adb -

testing - Detect whether test has failed within fixture -

Angularjs unit testing - ng-disabled not working when adding text to textarea -