This project is read-only.

Basic Usage

Using DotSerialize without any kind of customization doesn't get much simpler. The absolute simplest usage takes one line of code to either serialize or deserialize an object.
// First we declare a new instance of our example class (User in this case)
var user = new User("Sam", "Spade", "Detective");
// Now we serialize our new user to an xml file on back into a user instance
Serializer.SerializeToFile(@"C:\user.xml", user);
user = Seriailzer.DeserializeFromFile<User>(@"C:\user.xml");
The above example is using one of the static methods. If you wish to create a specific serializer instance, you may easily do this as well.
// First we declare a new instance of our example class (User in this case)
var user = new User("Sam", "Spade", "Detective");
// Now we serialize our new user to an xml file on back into a user instance
var serializer = new Serializer();
serializer.SerializeObjectToFile(@"C:\user.xml", user);
user = seriailzer.DeserializeObjectFromFile<User>(@"C:\user.xml");
All of the static methods simply call instance methods on a singleton instance of the serializer. In most cases users will never need to create an explicit instance of the serializer. Even if you wish to supply custom settings you can do this via the static instance as follows:
Serializer.Instance.Settings.OmitTypeWhenPossible = true;
// Now all future static calls will use our new settings change

Last edited Feb 1, 2015 at 6:30 AM by WiredWiz, version 6