C# class to XML and back to the class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C# class to XML and back to the class

Hello, I was wondering the best way to serialize a public class to an XML file and then de-serialize back to the same class. Thank you

7th Dec 2016, 6:57 PM
Rusty Shakelford
1 Answer
0
The best way (as I think) is to create abstract class with two methods - toXml() and fromXml(). First one will output XML object with serialized object (probably simple array with public properties and their values) and the second that takes XML object as a parametr and which produces instance of that object with public properties correctly set. You will use this new class as a parent for others which you want to serialize.
7th Dec 2016, 7:06 PM
Ondřej Doněk
Ondřej Doněk - avatar