/// <summary> /// Serializes event data properties /// </summary> /// <param name="eventData"></param> /// <returns></returns> public static byte[] SerializeProperties(this EventData eventData) { var writeStream = new BinaryTokenStreamWriter(); SerializationManager.Serialize(eventData.Properties.Where(kvp => !SkipProperties.Contains(kvp.Key)).ToList(), writeStream); var result = writeStream.ToByteArray(); writeStream.ReleaseBuffers(); return result; }
/// <summary> /// Creates a deep copy of an object /// </summary> /// <param name="source">The source object to be copy</param> /// <returns>The copy that was created</returns> public object DeepCopy(object source) { if (source == null) { return(null); } var writer = new BinaryTokenStreamWriter(); Serialize(source, writer, source.GetType()); var retVal = Deserialize(source.GetType(), new BinaryTokenStreamReader(writer.ToByteArray())); writer.ReleaseBuffers(); return(retVal); }
/// <inheritdoc /> public object DeepCopy(object source, ICopyContext context) { if (source == null) { return null; } var outputWriter = new BinaryTokenStreamWriter(); var serializationContext = new SerializationContext(context.GetSerializationManager()) { StreamWriter = outputWriter }; Serialize(source, serializationContext, source.GetType()); var deserializationContext = new DeserializationContext(context.GetSerializationManager()) { StreamReader = new BinaryTokenStreamReader(outputWriter.ToBytes()) }; var retVal = Deserialize(source.GetType(), deserializationContext); outputWriter.ReleaseBuffers(); return retVal; }
private static byte[] GetTokenBytes(StreamSequenceToken token) { var bodyStream = new BinaryTokenStreamWriter(); SerializationManager.Serialize(token, bodyStream); var result = bodyStream.ToByteArray(); bodyStream.ReleaseBuffers(); return result; }
/// <summary> /// Creates a deep copy of an object /// </summary> /// <param name="source">The source object to be copy</param> /// <returns>The copy that was created</returns> public object DeepCopy(object source) { if (source == null) { return null; } var writer = new BinaryTokenStreamWriter(); Serialize(source, writer, source.GetType()); var retVal = Deserialize(source.GetType(), new BinaryTokenStreamReader(writer.ToByteArray())); writer.ReleaseBuffers(); return retVal; }