Often I need to serialize an object, both for logging and debugging. This is one-way serialization - I donβt need to return it later, I just need to turn the object into a string in order to write it somewhere.
Yes, yes - so you should always override the ToString method. I know it. But I often deal with objects that I did not write and cannot change. In addition, I do not want to write or update the ToString method for each class that I write.
XML serialization seems to offer the perfect solution - just flatten this object in XML. But there are so many limitations, in particular, that you cannot serialize an IDictionary, and you must have a constructor without parameters. I can get around them in my classes, but - again - I often work with other classes of people.
So, what is the solution to get the full string representation of an object? Is there something simple that I'm missing?
c # serialization
Deane Dec 19 '12 at 15:23 2012-12-19 15:23
source share