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

sql - invalid in the select list because it is not contained in either an aggregate function -

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

How to start daemon on android by adb -