0
public abstract class Base
{
    //abstract methods
}

public class Derived1 : Base
{
    //method implementations
}

public class Derived2 : Derived1
{
    //method implementations
}

我正在使用“Derived2”进行序列化

        var serializer = new XmlSerializer(typeof(Derived2));
        serializer.Serialize(stringwriter, dataToSerialize);

它为Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.和提供了例外unable to generate xmldocument

现在,问题是,我不能在父实体上包含 xmlinclude 属性,因为我对父实体没有任何控制权。我可以完全控制大多数派生实体derived2

为此实现序列化的任何解决方案。

4

0 回答 0