In C#, how to instantiate an object against a class; but the class name is in a string variable?**
String stringNameOfClass = "SomeClass";
{stringNameOfClass} theObject = new {stringNameOfClass}();
In js, i think we could use eval()
var stringNameOfClass = "SomeClass";
eval('var theInstance = new ' + stringNameOfClass + '()');
theInstance.accessMethod();
[EDIT] Given: Classes name are unknown But methods are known
I can get all classes name in a given folder. Now I want to instantiate each of them accordingly by their namespace. Though, I know the method i'm interested in.
arrayOfString = getAllClassesByNamespace('TheNamespace','/path');
// now call testMe() per instance
foreach (string str in arrayOfString )
{
{str} arrayOfString[str] = new {str};
str.testMe();
//in js
eval('var obj_' + arrayOfString[str] + ' = new ' + arrayOfString[str] + '()');
//if first class found is TheClass.. this is what I want to do
TheClass obj_TheClass = new TheClass();
obj_TheClass.testMe();
}