[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination Optimizatio
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2006-08-03 21:24:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv17804/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: OptimizationOutput.cs Log Message: Implemented ISerializable interface for managing serialization / deserialization Index: OptimizationOutput.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/OptimizationOutput.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OptimizationOutput.cs 22 Aug 2005 22:21:39 -0000 1.2 --- OptimizationOutput.cs 3 Aug 2006 21:24:36 -0000 1.3 *************** *** 22,25 **** --- 22,27 ---- using System; + using System.Reflection; + using System.Runtime.Serialization; using System.Collections; *************** *** 31,35 **** /// </summary> [Serializable] ! public class OptimizationOutput : ArrayList { // public ArrayList BestGenomes --- 33,37 ---- /// </summary> [Serializable] ! public class OptimizationOutput : ArrayList, ISerializable { // public ArrayList BestGenomes *************** *** 37,42 **** --- 39,46 ---- // get { return this.bestGenomes; } // } + public OptimizationOutput() { + } /// <summary> *************** *** 48,51 **** --- 52,107 ---- base.Add( genomeRepresentation ); } + + /// <summary> + /// This constructor allows custom deserialization (see the ISerializable + /// interface documentation) + /// </summary> + /// <param name="info"></param> + /// <param name="context"></param> + protected OptimizationOutput( SerializationInfo info , StreamingContext context ) + { + // get the set of serializable members for this class and its base classes + Type thisType = this.GetType(); + MemberInfo[] mi = FormatterServices.GetSerializableMembers( + thisType , context); + + // deserialize the fields from the info object + for (Int32 i = 0 ; i < mi.Length; i++) + { + FieldInfo fieldInfo = (FieldInfo) mi[i]; + + // set the field to the deserialized value + try{ + fieldInfo.SetValue( this , + info.GetValue( fieldInfo.Name, fieldInfo.FieldType ) ); + } + catch(Exception ex) + {ex = ex;} + } + + } + + #region GetObjectData + /// <summary> + /// serialize the set of serializable members for this class and base classes + /// </summary> + /// <param name="info"></param> + /// <param name="context"></param> + void ISerializable.GetObjectData( + SerializationInfo info, StreamingContext context) + { + // get the set of serializable members for this class and base classes + Type thisType = this.GetType(); + MemberInfo[] mi = + FormatterServices.GetSerializableMembers( thisType , context); + + // serialize the fields to the info object + for (Int32 i = 0 ; i < mi.Length; i++) + { + info.AddValue(mi[i].Name, ((FieldInfo) mi[i]).GetValue(this)); + } + } + #endregion + } } |