/*
* Namespace Summary
* Copyright (C) 2005+ Bogdan Damian Constantin
* E-Mail: damianbcpetro@gmail.com
* WEB: http://www.sourceforge.net/projects/dataholder
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License 2.1 or later, as
* published by the Free Software Foundation. See the included License.txt
* or http://www.gnu.org/copyleft/lesser.html for details.
*
*/
using System;
namespace DataHolder.Containers{
internal delegate void PreSerializatonActionDelegate(object data, SerializationHelper srinfo);
/// <summary>
/// Contains the procedures needed to put an identification number on all the objects
/// contained inside the object that is serialized. The goal for this is to keep the
/// object referreces intact when the data is serialized/deserialized.
/// </summary>
public sealed class SerializationHelper
{
private ulong CurrentNo = ulong.MinValue;
public bool ClearSerialization = false;
internal static void GenericDataPreSerializatonAction(object data, SerializationHelper srinfo)
{
GenericData gd = (GenericData)data;
if(srinfo.ClearSerialization)
{
gd.SerializationNo = 0;
gd.InSerialization = false;
for(int i = 0; i < gd.Properties.Count; i++)
{
gd.Properties[i].PreSerializatonAction(gd[i], srinfo);
}
}
else if(!gd.InSerialization)
{
gd.InSerialization = true;
gd.SerializationNo = srinfo.CurrentNo;
srinfo.CurrentNo ++;
for(int i = 0; i < gd.Properties.Count; i++)
{
gd.Properties[i].PreSerializatonAction(gd[i], srinfo);
}
}
}
internal static void CollectionGenericDataPreSerializatonAction(object data, SerializationHelper srinfo)
{
GenericDataCollection gdc = (GenericDataCollection)data;
if(srinfo.ClearSerialization)
{
gdc.InSerialization = false;
for(int i = 0; i < gdc.Count; i++)
GenericDataPreSerializatonAction(gdc.GetObjectAt(i), srinfo);
}
else if(!gdc.InSerialization)
{
gdc.InSerialization = true;
for(int i = 0; i < gdc.Count; i++)
GenericDataPreSerializatonAction(gdc.GetObjectAt(i), srinfo);
}
}
}
}
|