Created
February 20, 2014 09:42
-
-
Save dlidstrom/9110140 to your computer and use it in GitHub Desktop.
Serialize into xml
This file contains 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
var serializer = new XmlSerializer(command.GetType()); | |
MemoryStream stream = null; | |
try | |
{ | |
stream = new MemoryStream(); | |
var streamRef = stream; | |
using (var writer = new XmlTextWriter(stream, Encoding.Unicode)) | |
{ | |
// stream is owned by writer and will be disposed automatically | |
stream = null; | |
serializer.Serialize(writer, command); | |
var xml = Encoding.Unicode.GetString(streamRef.ToArray()); | |
var changeLog = new ChangeLog(principal, command.GetType(), xml); | |
context.Changes.Add(changeLog); | |
} | |
} | |
finally | |
{ | |
if (stream != null) stream.Dispose(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment