P
Peter K
Hi
I have an object which I need to store in a "state holder" for the
application the object is to be used in. The "state holder" can only store
strings. (I cannot change this code and I must use it).
So I need to convert my object to a string to store in the state holder,
and provide a function to convert from a string to my object.
What are some good ways of approaching this?
Luckily, my object is very simple - it is really only a data container with
a few strings and numeric values. At the moment I have implemented a
"helper" class which reads my objects public properties and generates a
comma-separated string which I store in the state holder; and conversely a
conversion method the other way (which takes the comma separated string and
instantiates my object from that).
But maybe it would be better to incorporate this functionality in the
object itself? So I have a "ToString()", and a static "Parse" method or
something?
Thanks for any ideas,
Peter
I have an object which I need to store in a "state holder" for the
application the object is to be used in. The "state holder" can only store
strings. (I cannot change this code and I must use it).
So I need to convert my object to a string to store in the state holder,
and provide a function to convert from a string to my object.
What are some good ways of approaching this?
Luckily, my object is very simple - it is really only a data container with
a few strings and numeric values. At the moment I have implemented a
"helper" class which reads my objects public properties and generates a
comma-separated string which I store in the state holder; and conversely a
conversion method the other way (which takes the comma separated string and
instantiates my object from that).
But maybe it would be better to incorporate this functionality in the
object itself? So I have a "ToString()", and a static "Parse" method or
something?
Thanks for any ideas,
Peter