reflection - Get class properties by class name as string in C# -
can class properties if have class name string? entities in class library project , tried different methods type , assembly unable class instance.
var obj = (object)"user"; var type = obj.gettype(); system.activator.createinstance(type); object oform; var clsname = system.reflection.assembly.getexecutingassembly().createinstance("[namespace].[formname]"); type type = type.gettype("boentities.user"); object user = activator.createinstance(type);
nothing working
i suspect you're looking for:
type type = type.gettype("user"); object user = activator.createinstance(type);
note:
this inmscorlib
, executing assembly unless specify assembly in name it needs namespace-qualified name, e.g. myproject.user
edit: access type in different assembly, can either utilize assembly-qualified type name, or utilize assembly.gettype
, e.g.
assembly libraryassembly = typeof(someknowntypeinlibrary).assembly; type type = libraryassembly.gettype("librarynamespace.user"); object user = activator.createinstance(type);
(note haven't addressed getting properties nil else in question talked that. type.getproperties
should work fine.)
c# reflection .net-assembly
No comments:
Post a Comment