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. Managed C++/CLI
  4. Generating Runtime code(structs,classes) in C++/CLI

Generating Runtime code(structs,classes) in C++/CLI

Scheduled Pinned Locked Moved Managed C++/CLI
questioncsharpc++xmlhelp
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.
  • G Offline
    G Offline
    glitteringsound
    wrote on last edited by
    #1

    Hello, I need to generate structs and classes at run time in C#(might be in CLI) managed environment. Suppose I have all data and all data types associated with those data memebers of some class/struct. Now I need to generate structs/classes at runtime and after that I need to map data inside those runtime created structs fields. e.g I have read data from an XML file i.e BSTR field1,BSTR field2,BSTR field3,BSTR field4,BSTR field5,long field6. Now I need to create struct at runtime which has sizeof the sum of all fields (which I listed above) and then I can easily access those fields one by one. So that whole complete struct is formed. How can I solve this problem? Regards Usman

    N 1 Reply Last reply
    0
    • G glitteringsound

      Hello, I need to generate structs and classes at run time in C#(might be in CLI) managed environment. Suppose I have all data and all data types associated with those data memebers of some class/struct. Now I need to generate structs/classes at runtime and after that I need to map data inside those runtime created structs fields. e.g I have read data from an XML file i.e BSTR field1,BSTR field2,BSTR field3,BSTR field4,BSTR field5,long field6. Now I need to create struct at runtime which has sizeof the sum of all fields (which I listed above) and then I can easily access those fields one by one. So that whole complete struct is formed. How can I solve this problem? Regards Usman

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      glitteringsound wrote:

      e.g I have read data from an XML file i.e BSTR field1,BSTR field2,BSTR field3,BSTR field4,BSTR field5,long field6

      I don't think creating types at runtime is the correct way to do this. You should try to design your types in such a way that it can hold the data coming from XML file. For the example you have shown, I'd create a class which has a List which can hold all BSTR fields. If datatype of BSTR fields are not primitive, I'd create a separate type for BSTR and keep it in the above said list. Now if you have different data types for fields, you can keep a datatype identifier field which will tell you what type the value should be. This will help you to cast to the correct value before using. :)

      Best wishes, Navaneeth

      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