Skip to content
JaCraig edited this page Dec 10, 2014 · 1 revision

The serialization portion of the IO namespace, from a user standpoint is rather simple. By including Utilities.IO, the extension methods Serialize and Deserialize will be added. These extension methods allow you to access the various back end serializers registered with the system by either using the appropriate MIME type or the built in SerializationType class. Using the methods would look like this:

string SerializedData=new ExampleClass(){A=100,B="Hello world"}.Serialize<string,ExampleClass>();

The example above would serialize the class as JSON using the default DataContractJsonSerializer built into .Net. You can also specify the MIME type of the object, the built in serializers use the following MIME types:

  • JSON: application/json
  • SOAP: application/soap+xml
  • XML: text/xml
  • Binary: application/octet-stream
  • CSV: text/csv

JSON is simply the default that the system uses. These all use the built in serializers from .Net. If you would like to use your own (such as JSON.Net or ServiceStack.Text) you can easily do so by simply making a class that implements the Utilities.IO.Serializers.Interfaces.ISerializer interface or using one of the ones already created on NuGet. So if you write a JSON replacement, the system will pick that up and use that instead. You can also write serializers of other types not covered by the library (custom file format, etc) and it will find those as well.

Clone this wiki locally