Save run time values of class...

  • Thread starter Thread starter Nawoct
  • Start date Start date
N

Nawoct

Hi,

I have created a program that creates one to many classes at runtime. I would like to save these values with a sort of export function and be able to import them into the same program or another version of this program running on another computer.

So, my question is, is there a way to cycle through all the variables in a class and save their run time values to an .ini or XML file?

I could create the code to write the values out one at a time hard coded but that means that whenever I change a class I have to change the export/import code.

Cheers,

Tim
 
I have created a program that creates one to many classes at runtime.
I would like to save these values with a sort of export function and
be able to import them into the same program or another version of
this program running on another computer.

So, my question is, is there a way to cycle through all the variables
in a class and save their run time values to an .ini or XML file?

I could create the code to write the values out one at a time hard
coded but that means that whenever I change a class I have to change
the export/import code.

You can dynamically find all properties of any class via reflection.

Something like:

foreach(PropertyInfo pi in typeof(someobj).GetProperties())
{
// use pi.GetValue(someobj, null) to get value
}

But have you looked at XmlSerializer? It may already do
all you need!

Arne
 
Thank you Arne, for your reply. XmlSerializer does do just about all I want. Much simpler than I thought it would be.

Cheers,

Tim
 
Back
Top