由于只能给FixedDocument添加页面,所以我写了一个派生类:
public class CustomFixedDocument : FixedDocument
{
public void RemoveChild(object child)
{
base.RemoveLogicalChild(child);
}
}
替换 FixedDocument,它工作正常,直到我尝试打印文档并收到以下错误:
An unhandled exception of type 'System.Windows.Xps.XpsSerializationException' occurred in ReachFramework.dll
Additional information: Serialization of this type of object is not supported.
我过去没有那么多地使用序列化,并且已经阅读了它,但仍然无法解决问题。我也试过
[Serializable]
属性,但它没有任何区别。
谁能指导我正确的方向或有什么想法该怎么做?
最佳答案
如果查看检查是否支持某种类型的方法的反编译源代码,您将大致看到以下内容:
internal bool IsSerializedObjectTypeSupported(object serializedObject)
{
bool flag = false;
Type type = serializedObject.GetType();
if (this._isBatchMode)
{
if (typeof (Visual).IsAssignableFrom(type) && type != typeof (FixedPage))
flag = true;
}
else if (type == typeof (FixedDocumentSequence) || type == typeof (FixedDocument) || (type == typeof (FixedPage) || typeof (Visual).IsAssignableFrom(type)) || typeof (DocumentPaginator).IsAssignableFrom(type))
flag = true;
return flag;
}
这里你看到这个类型要么继承DocumentPaginator、Visual,要么完全是FixedDocument、FixedDocumentSequence、FixedPage类型。因此,无论您将使用什么可序列化属性,从 FixedDocument 继承的类型都不起作用,因此您必须找到不同的方法。我认为这是 XpsSerializationManager 中的错误,但也许有一些深层原因。
关于c# - 派生 FixedDocument 的序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32474210/