Save run time values of class...

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
 
A

Arne Vajhøj

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
 
N

Nawoct

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

Cheers,

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top