How do you construct an object without initializing it? (.net)
-
01-10-2019 - |
Pergunta
When you new an object in C# a few things must happen:
- memory for the object is created, and whatever other book-keeping CLR whats to do
- fields are initialized to default values
- 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?
Solução
Binary formatter uses methods of FormatterServices, like GetUninitializedObject.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow