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
  • 8,079
  • 12
  • 59
  • 107

1 Answers1

3

You can use the FormatterServices.GetUninitializedObject

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331