dynamic object creation using eval
-
I want to be able to create a range of objects using an Eval statement, but the name is not recognized. I'm creating a C# program using the .NET framework, and the compilers doesn't know what eval means. I'm trying to use a DataSet to create a bunch of objects using code similar to: Eval("TreeNode node" + ds.Tables["tableName"].Rows[i]["field1"].ToString() + " = new TreeNode(\"" + ds.Tables["tableName"].Rows[i]["field2"].ToString() + "\")"); But that's not gonna pass it seems. How can I achieve the desired affect using C# and the .NET Framework? I'm currently researching the System.Reflection class to see what my options are there. Any help from the outside world would be a great thing =) --chajadan aka charlie
-
I want to be able to create a range of objects using an Eval statement, but the name is not recognized. I'm creating a C# program using the .NET framework, and the compilers doesn't know what eval means. I'm trying to use a DataSet to create a bunch of objects using code similar to: Eval("TreeNode node" + ds.Tables["tableName"].Rows[i]["field1"].ToString() + " = new TreeNode(\"" + ds.Tables["tableName"].Rows[i]["field2"].ToString() + "\")"); But that's not gonna pass it seems. How can I achieve the desired affect using C# and the .NET Framework? I'm currently researching the System.Reflection class to see what my options are there. Any help from the outside world would be a great thing =) --chajadan aka charlie
Type t = Type.GetType("System.Windows.Forms.TreeNode");
object[] param = new object[0];
ConstructorInfo[] ci = t.GetConstructors();
object o = ci[0].Invoke
(BindingFlags.CreateInstance,null,param,null);Be sure to pass param with expected binding for one of the TreeNode constructor (in your case, that's a String object).