CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
BinaryFormatterWrapper.cs
Go to the documentation of this file.
1#if !NET5_0
2//-----------------------------------------------------------------------
3// <copyright file="BinaryFormatterWrapper.cs" company="Marimer LLC">
4// Copyright (c) Marimer LLC. All rights reserved.
5// Website: https://cslanet.com
6// </copyright>
7// <summary>Wraps the <see cref="BinaryFormatter"/></summary>
8//-----------------------------------------------------------------------
9using System.IO;
10using System.Runtime.Serialization.Formatters.Binary;
11
13{
22 {
23 private readonly BinaryFormatter _formatter =
24 new BinaryFormatter();
25
33 public object Deserialize(System.IO.Stream serializationStream)
34 {
35 return _formatter.Deserialize(serializationStream);
36 }
37
45 public object Deserialize(byte[] buffer)
46 {
47 using var serializationStream = new MemoryStream(buffer);
48 return _formatter.Deserialize(serializationStream);
49 }
50
57 public void Serialize(System.IO.Stream serializationStream, object graph)
58 {
59 _formatter.Serialize(serializationStream, graph);
60 }
61
66 public byte[] Serialize(object graph)
67 {
68 using var buffer = new MemoryStream();
69 _formatter.Serialize(buffer, graph);
70 buffer.Position = 0;
71 return buffer.ToArray();
72 }
73
79 public BinaryFormatter Formatter
80 {
81 get
82 {
83 return _formatter;
84 }
85 }
86 }
87}
88#endif
Wraps the BinaryFormatter in the ISerializationFormatter interface so it can be used in a standardize...
object Deserialize(byte[] buffer)
Converts a serialization stream into an object graph.
object Deserialize(System.IO.Stream serializationStream)
Converts a serialization stream into an object graph.
BinaryFormatter Formatter
Gets a reference to the underlying BinaryFormatter object.
byte[] Serialize(object graph)
Converts an object graph into a byte stream.
void Serialize(System.IO.Stream serializationStream, object graph)
Converts an object graph into a byte stream.
Defines an object that can serialize and deserialize object graphs.