I am implementing IXmlSerializable
in an immutable class. To keep the class immutable I am implementing the interface explicitly, so as to hide the methods, and using a static ReadXml()
method which encapsulates the ReadXml(XmlReader reader)
method and, instead, returns a new instance of my class. However, and supposing the class is called ClassA
, the way I am forced to implement IXmlSerializable
implies that the statement
((ClassA)((IXmlSerializable)(ClassAObject)).ReadXml(reader))
actually mutates the ClassAObject
since, inside IXmlSerializable.ReadXml
I am assigning to parameters of an already created object. That being, can ClassAObject
still be considered immutable?