[Serializable]
class MeasureData
{
public MeasureLineData measureLineData = new MeasureLineData();
public HShapeModel MyShapeModel = new HShapeModel();
public double MyShapeModelRow;//模板位置
public double MyShapeModelCol;
public double MyShapeModelPhi;
public Dictionary<string, MeasureLineData> MeasureLineDataDic = new Dictionary<string, MeasureLineData>();
[NonSerialized ]
public Dictionary<string, LineData> LineDataDic = new Dictionary<string, LineData>();
//标记该方法在序列化期间被调用
[OnSerializing]
private void OnSerializing(StreamingContext context)
{
//举例:在序列化前,修改任何需要修改的状态
//要么为null 要么里面有正确的赋值, 不能只是new个对象 IsInitialized
//判断是否已经初始化 具有真正的对象指针 在序列化对象里存储Halcon图元 对象的特点
if (MyShapeModel != null && !MyShapeModel.IsInitialized())
{
MyShapeModel = null;
}
}
//标记该方法在序列化之后被调用
[OnSerialized]
private void OnSerialized(StreamingContext context)
{
//举例:在序列化之后,恢复任何需要恢复的状态
}
//标记该方法在反序列化期间被调用
[OnDeserializing]
private void OnDeserialing(StreamingContext context)
{
//举例:在反序列化期间,为字段设置默认值
}
//标记该方法在反序列化之后被调用
[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
if (MyShapeModel == null)
{
MyShapeModel = new HShapeModel();
}
if (LineDataDic == null)
{
LineDataDic = new Dictionary<string, LineData>();
}
}
}