Implement serialization
authorNeale Ferguson <neale@sinenomine.net>
Mon, 21 Nov 2011 21:32:14 +0000 (16:32 -0500)
committerNeale Ferguson <neale@sinenomine.net>
Mon, 21 Nov 2011 21:32:14 +0000 (16:32 -0500)
mcs/class/System.Core/System.Collections.Generic/HashSet.cs

index 7f8bac21887ab19ac2897103788dae139e91aee9..39047dcd35804ffcc0443e90c7c3f49f7e7a9337 100644 (file)
@@ -572,22 +572,51 @@ namespace System.Collections.Generic {
                        return setComparer;
                }
 
-               [MonoTODO]
                [SecurityPermission (SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
                public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
                {
-                       throw new NotImplementedException ();
+                       if (info == null) {
+                               throw new ArgumentNullException("info");
+                       }
+                       info.AddValue("Version", generation);
+                       info.AddValue("Comparer", comparer, typeof(IEqualityComparer<T>));
+                       info.AddValue("Capacity", (table == null) ? 0 : table.Length);
+                       if (table != null) {
+                               T[] tableArray = new T[table.Length];
+                               CopyTo(tableArray);
+                               info.AddValue("Elements", tableArray, typeof(T[]));
+                       }
                }
 
-               [MonoTODO]
                public virtual void OnDeserialization (object sender)
                {
-                       if (si == null)
-                               return;
+                       if (si != null)
+                       {
+                               generation = (int) si.GetValue("Version", typeof(int));
+                               comparer = (IEqualityComparer<T>) si.GetValue("Comparer", 
+                                                                             typeof(IEqualityComparer<T>));
+                               int capacity = (int) si.GetValue("Capacity", typeof(int));
+
+                               empty_slot = NO_SLOT;
+                               if (capacity > 0) {
+                                       table = new int[capacity];
+                                       slots = new T[capacity];
+
+                                       T[] tableArray = (T[]) si.GetValue("Elements", typeof(T[]));
+                                       if (tableArray == null) 
+                                               throw new SerializationException("Missing Elements");
+
+                                       for (int iElement = 0; iElement < tableArray.Length; iElement++) {
+                                               Add(tableArray[iElement]);
+                                       }
+                               } else 
+                                       table = null;
 
-                       throw new NotImplementedException ();
+                               si = null;
+                       }
                }
 
+
                IEnumerator<T> IEnumerable<T>.GetEnumerator ()
                {
                        return new Enumerator (this);