When implementing IXmlSerializable, how to only override either ReadXml or WriteXml and not both?

后端 未结 2 523
耶瑟儿~
耶瑟儿~ 2021-02-01 09:52

I would like to implement IXmlSerializable on a class and only override either ReadXml or WriteXml, but not both. If I didn\'t implement IXMLSerializable on this class, the XML

2条回答
  •  不要未来只要你来
    2021-02-01 10:06

    You will need to implement both methods, but that is the full extent of your responsibility (as far as the compiler is concerned). You can return null or throw an exception in the method that you will not be using.

    EDIT

    I'd like the default behavior to apply for the non-overridden case.

    What default behavior are you referring to? Since you are implementing an interface, there is no default behavior.

提交回复
热议问题