2

Is it possible to do this?

I have a class with validation logic in the constructor. For general use I want to enforce this constructor.

However, when deserializing the so said class, I want to be able to bypass that validation logic and simply reserve the memory space without running any construction routine (like malloc in c++).The properties will then be mapped manually using reflection, after the object has been instantiated. Is this possible in C#?

Alwyn
  • 7,801
  • 12
  • 52
  • 106

1 Answers1

3

You can use the FormatterServices.GetUninitializedObject

Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319