如何在 silverlight 中序列化 IEnumerable 对象
ICloneable 在 Silverlight 4 中不可用(我不知道 1/2/3 或即将推出的版本)。它已从 Silverlight 4 的公共 API 中删除。
我有这些类:
public class LayerDto
{
public MetaItemDtoList MetaItems;
}
public class MetaItemDtoList : System.Collections.ObjectModel.ObservableCollection
{
}
我想创建 IEnumerable
的克隆。 我正在尝试这样做。但没有得到元项目
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;
}
}
ICloneable is not available in Silverlight 4(I don't know about 1/2/3 or upcoming version) . It is removed from Silverlight 4's public APIs.
I have these classes :
public class LayerDto
{
public MetaItemDtoList MetaItems;
}
public class MetaItemDtoList : System.Collections.ObjectModel.ObservableCollection
{
}
I want to create clone of IEnumerable<LayerDto>
.
I am trying to do this. but not getting 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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论