序列化:在抽象类中定义的XmlRoot元素名称

时间:2017-02-16 14:17:00

标签: c# xml-serialization

我为API项目序列化XML(使用System.Xml.Serialization)输出,并希望所有响应的根元素都为Response

我有一个ResponseModelBase课,我希望在以下方面处理:

[XmlRoot(ElementName = "Response")]
public abstract class ResponseModelBase
{
    // other common stuff
}

然后我使用一个具体的类:

public class CustomerPostResponseModel : ResponseModelBase
{
    // other stuff here
}

使用此设置,当我返回具体类时,XML根目录为CustomerPostResponseModel,我希望它在Response

我可以"修复"这是通过将XmlRoot属性应用于具体类,但更倾向于在抽象级别指定它。

我有办法吗?感谢

0 个答案:

没有答案