IXmlSerializable and inheritance

前端 未结 2 522
死守一世寂寞
死守一世寂寞 2021-01-13 21:21

Let\'s say that I have two classes, a base class and a derived class. They are fairly simple classes, and mainly just act as data structures (with the derived class obviousl

2条回答
  •  余生分开走
    2021-01-13 21:24

    Well, I've managed to do what you're trying to do using the DataContractSerializer.

    You should either put KnownTypes attribute on the base classes you want to serialize, or better yet, use a DataContractResolver to find the derived types.

    I've seen a generic implementation on the web, I'll post it here if I find it again.

    Edit

    Found it here

    Let me know if you need more help.

提交回复
热议问题