如何在silverlight中序列化IEnumerable对象

时间:2011-10-13 12:12:20

标签: c# .net silverlight silverlight-4.0

ICloneable在Silverlight 4中不可用(我不知道1/2/3或即将推出的版本)。它已从Silverlight 4的公共API中删除。

我有这些课程:

public class LayerDto 

{

public MetaItemDtoList MetaItems;

}

public class MetaItemDtoList : System.Collections.ObjectModel.ObservableCollection 
{ 
}

我想创建IEnumerable<LayerDto>的克隆。 我想这样做。但没有得到metaItems

public static IEnumerable Clone(IEnumerable<LayerDto> source)

{
        IEnumerable<LayerDto> layers;

        DataContractSerializer serializer = new DataContractSerializer(typeof(IEnumerable<LayerDto>));
        using (MemoryStream ms = new MemoryStream())
        {
            serializer.WriteObject(ms, source);
            ms.Seek(0, SeekOrigin.Begin);
            //return (IEnumerable<LayerDto>)serializer.ReadObject(ms);
            layers = (IEnumerable<LayerDto>)serializer.ReadObject(ms);
            return layers;
        }
 }

0 个答案:

没有答案