开发者

How can I set the StreamingContext in Silverlight DataContractSerizer?

开发者 https://www.devze.com 2023-03-25 04:33 出处:网络
I need to do a deep copy in Silverlight, which I开发者_C百科 can do with the tried and tested serialize/deserialize approach. The copied objects aren\'t exact clones - they need to have some of their

I need to do a deep copy in Silverlight, which I开发者_C百科 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
  }       
}

where the StreamingContext is set up using a NetDataContractSerializer:

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

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

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'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消