XmlSerializer: “The type 'Type' may not be used in this context”

后端 未结 3 1945
無奈伤痛
無奈伤痛 2021-01-03 03:29

I\'m trying to figure out how to serialize any class using the XmlSerializer, without using the XmlInclude attribute. Generally works, but with the followi

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-03 04:25

    First of all should not it be like this:

    //[XmlInclude(typeof(B))]
    [Serializable]
    public class A : ReactListObject
    {
        public int AValue = 1;
    }
    
    [XmlInclude(typeof(A))]
    public class B : A
    {
        public int BValue = 2;
    }
    

提交回复
热议问题