/// <summary> /// Serializes an object that implements IMDSSerializable and returns serialized byte array. /// </summary> /// <param name="serializableObject">Object to serialize</param> /// <returns>Serialized object as byte array</returns> public static byte[] SerializeToByteArray(IMDSSerializable serializableObject) { var stream = new MemoryStream(); new MDSDefaultSerializer(stream).WriteObject(serializableObject); return(stream.ToArray()); }
/// <summary> /// Serializes an object that implements IMDSSerializable interface. /// Object may be null. /// </summary> /// <param name="serializableObject">object to serialize</param> public void WriteObject(IMDSSerializable serializableObject) { if (serializableObject == null) { _stream.WriteByte(0); return; } _stream.WriteByte(1); serializableObject.Serialize(this); }
/// <summary> /// Serializes an object that implements IMDSSerializable to a Stream. /// </summary> /// <param name="stream">Stream to write serialized object</param> /// <param name="serializableObject">Object to serialize</param> public static void SerializeToStream(Stream stream, IMDSSerializable serializableObject) { new MDSDefaultSerializer(stream).WriteObject(serializableObject); }
/// <summary> /// Serializes an array that all items implements IMDSSerializable interface. /// Object array may be null or empty. /// </summary> /// <param name="serializableObjects">objects to serialize</param> public void WriteObjectArray(IMDSSerializable[] serializableObjects) { if (serializableObjects == null) { WriteInt32(-1); } else { WriteInt32(serializableObjects.Length); for (var i = 0; i < serializableObjects.Length; i++) { WriteObject(serializableObjects[i]); } } }
/// <summary> /// Serializes an object that implements IMDSSerializable interface. /// Object may be null. /// </summary> /// <param name="serializableObject">object to serialize</param> public void WriteObject(IMDSSerializable serializableObject) { if (serializableObject == null) { _stream.WriteByte(0); return; } _stream.WriteByte(1); serializableObject.Serialize(this); }