.NET XML Serialization and inheritance

前端 未结 6 492
别跟我提以往
别跟我提以往 2021-02-04 12:08

I have structure like this:

public interface A
{
    public void method();
}

public class B : A
{
}

public class C : A
{
}

List list;
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 12:27

    XmlSerializer does not work with interfaces. So you can:

    Convert interface to abstract class and then use XmlIncludeAttribute for it or provide KnownTypes to XmlSerializer

    or

    Implement IXmlSerializable for the parent type

    or

    Consider using DataContractSerializer from .NET 3.0

提交回复
热议问题