我正在尝试向 XmlSerializor 添加一些提示,以便它可以序列化/反序列化接口。我不能将XmlIncludeAttribute添加为类的装饰,而是想将序列化覆盖传递给 XmlSerializor:
var _xs = new XmlSerializer(typeof(Model.ISession), SerializationOverrides());
SerializationOverrides()
看起来像这样:
private static XmlAttributeOverrides SerializationOverrides()
{
var overrides = new XmlAttributeOverrides();
overrides.Add(typeof(Model.ISession), XmlInclude(typeof(Model.Session)));
return overrides;
}
到目前为止,一切都很好。该XmlInclude(...)
方法创建了一个新的XmlAttributes对象,但我不知道如何添加XmlIncludeAttribute属性。
private static XmlAttributes XmlInclude(Type type)
{
var attrs = new XmlAttributes();
attrs....Add(new XmlIncludeAttribute(type)); // Add how?????
return attrs;
}
建议?