Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. dynamic object creation using eval

dynamic object creation using eval

Scheduled Pinned Locked Moved C#
csharpquestiondotnethelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chajadan
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • C chajadan

      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

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      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).

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups