views:

25

answers:

2

Short and simple: If I have an object with many values == to their default constructor values, will a serialization with a binary formatter omit them in the resulting file to save space? I'm figuring, since the value is known from the class definition anyway.

+2  A: 

I guess the answer is no, because how the serializer is supposed to know the value you assign in the constructor? It could be assigned using reflection or read from a database. If by default value you mean default(T), then it is a different story.

Darin Dimitrov
I guess you have a point there about the serializer not knowing the default.
Niklas Winde
+1  A: 

Wouldn't guess so by default, except perhaps for values on which DefaultValueAttribute is used? Why don't you try it and see?

peSHIr
I'll try that, didn't know about that attribute.
Niklas Winde
I know it is taken into account in the VS visual designer and VS property grid on usercontrols. When property with this attribute has default value, initialisation code for it is not put into generated form initialisation code by designer. Also, it enables the Reset context menu item on properties in the property grid that lets you reset the property to its default value.
peSHIr