0

When you new an object in C# a few things must happen:

  1. memory for the object is created, and whatever other book-keeping CLR whats to do
  2. fields are initialized to default values
  3. the constructor is invoked

Serialization frameworks seem to have some magical way to do 1 without doing 2 and 3. Or maybe it's not so magical after all. How would you do the same (skip 2 and 3) if you are writing your own deserialization code?

Tim Lovell-Smith
  • 15,310
  • 14
  • 76
  • 93
  • 2
    possible duplicate of [C#: Create object instance without invoking constructor?](http://stackoverflow.com/questions/296584/c-create-object-instance-without-invoking-constructor) – Brian Rasmussen Aug 25 '10 at 04:53

1 Answers1

0

Binary formatter uses methods of FormatterServices, like GetUninitializedObject.

desco
  • 16,642
  • 1
  • 45
  • 56