.NET XML Serialization and inheritance

前端 未结 6 501
别跟我提以往
别跟我提以往 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:36

    Assuming you're using the built in .net XML serialization you should take a look at the following attribute:

    System.Xml.Serialization.XmlIncludeAttribute
    

    It allows you to instruct the serializer to include other types when serializing/deserializing.

    Adding new types to the list and not updating the serialization meta data is a common source of mistakes, make sure you have adequate test coverage.

提交回复
热议问题