本文介绍了是否有可能无需在WCF一个无参数的构造函数序列化对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,私人参数的构造函数的作品,但怎么样的对象,无参数构造函数?

I know that a private parameterless constructor works but what about an object with no parameterless constructors?

我想从第三方库暴露类型,所以我有过的类型定义没有控制权。

I would like to expose types from a third party library so I have no control over the type definitions.

如果有一种方法是什么最容易?例如。我没有什么要创建一个子类。

If there is a way what is the easiest? E.g. I don't what to have to create a sub type.

编辑:

我正在寻找的是类似的定制这里显示的水平:http://msdn.microsoft.com/en-us/magazine/cc163902.aspx虽然我不想不得不求助于流序列化/反序列化。

What I'm looking for is something like the level of customization shown here: http://msdn.microsoft.com/en-us/magazine/cc163902.aspxalthough I don't want to have to resort to streams to serialize/deserialize.

推荐答案

您不能真正使任意类型序列化;在某些情况下(的XmlSerializer ,例如)运行时暴露的选择欺骗的属性。但的DataContractSerializer 不允许这样做。可行的方案:

You can't really make arbitrary types serializable; in some cases (XmlSerializer, for example) the runtime exposes options to spoof the attributes. But DataContractSerializer doesn't allow this. Feasible options:

  • 躲在自己的类型的的类的序列化(大量的工作)
  • 提供二进制格式化代理人(yeuch)
  • 在编写自己的序列化的核心(大量的工作,以得到正确的)
  • hide the classes behind your own types that are serializable (lots of work)
  • provide binary formatter surrogates (yeuch)
  • write your own serialization core (a lot of work to get right)

从本质上讲,如果事情是不是的设计的系列化,很少框架会的的序列化它。

Essentially, if something isn't designed for serialization, very little of the framework will let you serialize it.

这篇关于是否有可能无需在WCF一个无参数的构造函数序列化对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 18:25