如何在Silverlight DataContractSerizer中设置StreamingContext? [英] How can I set the StreamingContext in Silverlight DataContractSerizer?

查看:71
本文介绍了如何在Silverlight DataContractSerizer中设置StreamingContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Silverlight中进行深层复制,可以使用经过实践检验的序列化/反序列化方法进行复制。复制的对象不是精确的克隆-它们需要在副本上修改其某些属性。

I need to do a deep copy in Silverlight, which I can do with the tried and tested serialize/deserialize approach. The copied objects aren't exact clones - they need to have some of their properties modified on the copy.

我应该能够执行以下操作:

I should be able to do something like this:

[OnDeserialized()]
public void OnDeserializedMethod(StreamingContext context)
{
  if (context.State == StreamingContextStates.Clone)
  {
    //stuff
  }       
}

其中 StreamingContext 是使用 NetDataContractSerializer 设置的:

NetDataContractSerializer ds = new NetDataContractSerializer(new StreamingContext(StreamingContextStates.Clone));

Silverlight没有 NetDataContractSerializer :-(。

Silverlight doesn't have a NetDataContractSerializer though :-(.

那么我有什么方法可以在上设置 StreamingContext DataContractSerializer 给我一些有用的东西吗?我不能只是盲目地将更改应用于每个序列化操作,而只是在特定的情况下进行复制。

So is there any way I can set the StreamingContext on the DataContractSerializer to give me something to work with? I can't just blindly apply my changes to every serialize operation, it's only on the specific case of a copy.

或者,是否有另一种方法可以给我类似的反序列化过程挂钩,以便我可以处理数据?

Or, alternatively, is there another method that gives me similar hooks into the (de)serialization process so I can play with the data?

(I '已经研究了实现 IDataContractSurrogate 的方法,但是a)痛苦而b)Silverlight没有任何一个...)

(I've looked into implementing IDataContractSurrogate but a) it was painful and b) Silverlight doesn't have one of those either...)

推荐答案

我得出的结论是你做不到,所以我猜想有一种替代方法。

I've come to the conclusion that you can't do it, so I guess an alternative approach is in order.

这篇关于如何在Silverlight DataContractSerizer中设置StreamingContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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