public static byte[] ToBytes(this EntityDefinition entity)
 {
     byte[] result = null;
     using (var stream = entity.ToStream())
     {
         result = stream.ToArray();
     }
     return(result);
 }
        /// <summary>
        /// user provides stream
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="stream"></param>
        /// <returns>MemoryStream - remember to dispose!</returns>
        public static void ToStream(this EntityDefinition entity, Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            var formatter = new BinaryFormatter();

            formatter.Serialize(stream, entity);
        }
        public static void ToCompressedStream(this EntityDefinition entity, Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using (var gzipStream = new GZipStream(stream, CompressionMode.Compress, true))
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(gzipStream, entity);
                gzipStream.Flush();
            }
        }
        public static void Write(this Stream stream, EntityDefinition entity)
        {
            var formatter = new BinaryFormatter();

            formatter.Serialize(stream, entity);
        }
 public static string ToJson(this EntityDefinition entity)
 {
     return(JsonConvert.SerializeObject(entity, _settings));
 }