Sunday 15 June 2014

c# - get assembly by class name -



c# - get assembly by class name -

is there way assembly contains class name testclass? know class name, can't create instance of that. and

type objecttype = assembly.gettype("testclass");

didn't work me.

from type objecttype in question, assume actually after type name (not assembly); assuming assembly loaded , type name unique, linq may help:

type objecttype = (from asm in appdomain.currentdomain.getassemblies() type in asm.gettypes() type.isclass && type.name == "testclass" select type).single(); object obj = activator.createinstance(objecttype);

however, may improve work assembly-qualified name instead of type name.

c# reflection

No comments:

Post a Comment