派生 FixedDocument 的序列化 [英] Serialization of derived FixedDocument

查看:73
本文介绍了派生 FixedDocument 的序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于FixedDocument只能添加页面,所以我写了一个派生类:

Since you can only add pages to a FixedDocument, I wrote a derived class:

public class CustomFixedDocument : FixedDocument
{
    public void RemoveChild(object child)
    {
        base.RemoveLogicalChild(child);
    }
}

替换FixedDocument,它工作正常,直到我尝试打印文档并收到以下错误:

to replace FixedDocument, which works fine, until I try to print the document and receive the following error:

未处理的异常类型'System.Windows.Xps.XpsSerializationException' 发生在ReachFramework.dll

An unhandled exception of type 'System.Windows.Xps.XpsSerializationException' occurred in ReachFramework.dll

补充信息:此类对象的序列化不是支持.

Additional information: Serialization of this type of object is not supported.

我过去很少使用序列化,并且已经阅读了它,但仍然无法解决问题.我也试过了

I haven't worked with serialization that much in the past and have read up on it but still can't solve the issues. I have also tried the

[Serializable]

属性,但没有任何区别.

attribute, but it doesn't make any difference.

任何人都可以指导我朝着正确的方向前进或有什么想法可以做什么吗?

Can anybody guide me in the correct direction or have any ideas what to do?

推荐答案

如果您查看检查是否支持某种类型的方法的反编译源代码,您将大致看到以下内容:

If you look at decompiled source code of the method which checks if certain type is supported, you will see roughly the following:

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 中的一个错误,但也许有一些深层原因.

Here you see that this type should either inherit DocumentPaginator, Visual, or be exactly of type FixedDocument, FixedDocumentSequence, FixedPage. So, types inherited from FixedDocument will not work, whatever serializable attributes you will use, so you have to find a different approach. I think that is a bug in XpsSerializationManager, but maybe there is some deep reason.

这篇关于派生 FixedDocument 的序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆