c# - Xml deserialize does unwanted initialization -
i have class contains list. in constructor add default object list.
class { list<b> list; public a() { list = new list<b>(); b b = new b(); list.add(b); } }
but seems when xmlserializer
deserialize xml file containing a
object, loaded object have 2 b
object in list. guess calls constructor again , constructor adds next b
why happens? how can avoid it?
try overloaded constructor. 1 takes nothing , adds nothing list, can used when deserializing. other takes b , adds b list.
Comments
Post a Comment