Skip to content

Commit

Permalink
Re-wrap memory streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Allcharles committed Mar 19, 2020
1 parent 46d3e0d commit a772ad6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Acoustics.Shared/Extensions/ExtensionsGeneral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public static object BinaryDeserialize(this byte[] bytes)
}

var formatter = new BinaryFormatter();
using var stream = new MemoryStream(bytes);
return formatter.Deserialize(stream);
using (var stream = new MemoryStream(bytes))
{
return formatter.Deserialize(stream);
}
}

/// <summary>
Expand All @@ -66,9 +68,10 @@ public static object BinaryDeserialize(this byte[] bytes, SerializationBinder bi
}

var formatter = new BinaryFormatter { Binder = binder };

using var stream = new MemoryStream(bytes);
return formatter.Deserialize(stream);
using (var stream = new MemoryStream(bytes))
{
return formatter.Deserialize(stream);
}
}

/// <summary>
Expand All @@ -82,10 +85,12 @@ public static object BinaryDeserialize(this byte[] bytes, SerializationBinder bi
public static byte[] BinarySerialize(this object o)
{
var formatter = new BinaryFormatter();
using var stream = new MemoryStream();
formatter.Serialize(stream, o);
stream.Flush();
return stream.ToArray();
using (var stream = new MemoryStream())
{
formatter.Serialize(stream, o);
stream.Flush();
return stream.ToArray();
}
}

/// <summary>
Expand Down

0 comments on commit a772ad6

Please sign in to comment.