C# 子对象的Deepclone问题需要深度序列化
我在通过序列化/反序列化方式实现DeepClone时遇到了一个问题。 事实是: 我希望我的类OwnDataset通过以下2个公共过程(构造函数和GetObjectData)声明其deepclone实例:C# 子对象的Deepclone问题需要深度序列化,c#,serialization,clone,C#,Serialization,Clone,我在通过序列化/反序列化方式实现DeepClone时遇到了一个问题。 事实是: 我希望我的类OwnDataset通过以下2个公共过程(构造函数和GetObjectData)声明其deepclone实例: protected OwnDataSet(SerializationInfo info, StreamingContext context) : base(info, context) { DSType = DataSetType.Standard; Attr
protected OwnDataSet(SerializationInfo info, StreamingContext context)
: base(info, context)
{
DSType = DataSetType.Standard;
Attributes =
new OwnAttributeList(
(List<OwnAttribute>)
info.GetValue("Attributes", typeof (List<OwnAttribute>)));
IsLinkedDS = info.GetBoolean("IsLinkedDS");
PCAForScores = (PCA)info.GetValue("PCAForScores", typeof(PCA));
Levels = (string[])info.GetValue("Levels", typeof(string[]));
}
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
public override void GetObjectData(SerializationInfo info,
StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("Attributes", new List<OwnAttribute>(Attributes), typeof(List<OwnAttribute>));
info.AddValue("IsLinkedDS", IsLinkedDS);
info.AddValue("PCAForScores", PCAForScores);
info.AddValue("Levels", Levels);
}
请注意OwnDataset有其属性。其中一个名为Attributes,其类型为OwnAttributeList—OwnAttribute对象的集合。
调用以获取OwnDataset的deepclone实例时,在构造函数中,所有类型简单的属性,例如IsLink Edds boolean、Levels string[]。。。他成功地离开了。好啊
但对于更复杂的类型化对象,例如AttAttributes类型化的OwnAttributeList,其输出错误。集合中的元素数仍然正确,但每个元素都为NULL!
有这方面经验的人请帮助我或给我一些提示。我忘了什么吗?
感谢您的关注,并等待您的帮助。OwnAttribute是否提供序列化信息、StreamingContext这实际上是一个数据集吗?或者只是名为*DataSet@Marc Gravell的东西:是的,OwnDataset继承自CustomDataset继承自System.Data.DataSet。但在OwnDataset及其父CustomDataset中,我已经使用SerializationInfo参数SerializationInfo、StreamingContext和方法GetObjectData从ISerializable建立了构造函数。