views:

45

answers:

2
var mystring = "MyCompany.MyType.Localization.Strings.MyString"

In C#, is there a way I could fill it up such that

var abc = GetReflectedValue(mystring);

Is reflection the only way? (how?) Or any more efficient ways?

A: 

It's not 100% clear what you are trying to do. Do you mean create an instance of an object given only it's string type name? If so, use Activator.CreateInstance:

var item = Activator.CreateInstance(Type.GetType(mystring));
Mitch Wheat
Type.GetType() keeps saying null, it seems like my shared dll may not be loaded. Does my assembly need to be loaded for this to work?
A: 

as Mitch Said u can use Activator.CreateInstance(Type.GetType ..., Also ur type should be in one of a dlls in the execution path, u can copy the dll in output folder or make it com visible and register it in GAC, ...

SaeedAlg