.NET XML Serialization and inheritance

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

    For your case make an abstract class that implements your interface like:

    abstract class Abs : A
    

    and then derive your classes from Abs

    public class B : Abs
    public class C : Abs
    

    and List list;

    now use XmlIncludeAttribute to add your types into the XmlSerializer's type array.

提交回复
热议问题