src/SyncTool.FileSystem/main/SerializationExtensions.cs
/// <summary>
/// Serializes the object to JSON and writes it to the specified stream
/// </summary>
Serializes the object to JSON and writes it to the specified stream
Serializes the object to JSON and writes it to the specified stream
public static void WriteTo(this object obj, Stream stream)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            var serializer = new JsonSerializer();
            var streamWriter = new StreamWriter(stream);
            var jsonWriter = new JsonTextWriter(streamWriter) { Formatting = Formatting.Indented };
            serializer.Serialize(jsonWriter, obj);
            jsonWriter.Flush();
            streamWriter.Flush();
        }
public static void WriteTo ( this object obj , Stream stream ) { if ( obj == null ) { throw new ArgumentNullException ( nameof ( obj ) ) ; } if ( stream == null ) { throw new ArgumentNullException ( nameof ( stream ) ) ; } var serializer = new JsonSerializer ( ) ; var streamWriter = new StreamWriter ( stream ) ; var jsonWriter = new JsonTextWriter ( streamWriter ) { Formatting = Formatting . Indented } ; serializer . Serialize ( jsonWriter , obj ) ; jsonWriter . Flush ( ) ; streamWriter . Flush ( ) ; }
Serializes the object to JSON and writes it to the specified stream
Serializes the object to JSON and writes it to the specified stream
object
this
stream
Stream