Created
April 18, 2012 20:05
-
-
Save chgeuer/2416183 to your computer and use it in GitHub Desktop.
Serialize using a DataContractSerializer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string DataContractSerialize(object serializableObject) | |
{ | |
if (serializableObject == null) | |
{ | |
return null; | |
} | |
using (MemoryStream memoryStream = new MemoryStream()) | |
{ | |
DataContractSerializer serializer = new DataContractSerializer(serializableObject.GetType()); | |
serializer.WriteObject(memoryStream, serializableObject); | |
return Encoding.UTF8.GetString(memoryStream.ToArray()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment