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

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -