1

I use BinaryWriter to write my items to stream. How i can write object to Stream and back without BinaryFormatter?

4
  • 1
    Use an XmlFormatter :-D Commented Apr 1, 2014 at 12:00
  • =) XmlFormatter is too slow... Commented Apr 1, 2014 at 12:01
  • Well why don't you want to use BinaryFormatter? What are your actual requirements here? Commented Apr 1, 2014 at 12:04
  • Write your own formatter or use other available options Commented Apr 1, 2014 at 12:06

2 Answers 2

1

Simply, you need to (one of):

  • write code that (de)serializes each field/property in turn, using the (reader/)writer API over each member
  • write code that automates the first option at compile-time, generating C#
  • write code that automates the first option at runtime, generating IL (or C# which it compiles)

Taking into account nested objects, nulls, reference-tracking, collections, lists, serialization callbacks, string value-vs-reference equality, conversion operators, custom iterators, surrogates, serialization-contexts, IO buffering, etc.

Alternatively, use one of the many binary serializers that exist that already do that. I'm hugely biased as the author, but I'd use protobuf-net.

Sign up to request clarification or add additional context in comments.

Comments

0

My biased answer is http://binaryserializer.codeplex.com.

It allows you to define bindings to control the exact format of the data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.