Dab*_*rnl 2 .net c# serialization
下面的简单类继承自HashSet,因此必须实现ISerialization成员(以非标准方式).当我尝试序列化然后反序列化Group的实例时,我得到以下异常:
测试方法UtilitiesTests.GroupTest.SerializeTest抛出异常:System.Reflection.TargetInvocationException:Het doel van een aanroep heeft een uitzondering veroorzaakt.---> System.Runtime.Serialization.SerializationException:Lid nameprop是niet gevonden ..
不幸的是,这是荷兰语.这意味着无法找到成员"nameprop"!怎么了??
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Grouping
{
[Serializable]
public class Group<T> : HashSet<T>
{
public Group(string name)
{
Name = name;
}
protected Group(){}
protected Group(SerializationInfo info, StreamingContext context):base(info,context)
{
Name = info.GetString("nameprop");
}
protected new void GetObjectData(SerializationInfo info,StreamingContext context)
{
base.GetObjectData(info,context);
info.AddValue("nameprop", Name);
}
public string Name { get; private set; }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2827 次 |
| 最近记录: |