public virtual void OnDeserialization(Object sender)
        {
            SerializationInfo siInfo;

            HashHelpers.SerializationInfoTable.TryGetValue(this, out siInfo);

            if (siInfo == null)
            {
                // It might be necessary to call OnDeserialization from a container if the container object also implements
                // OnDeserialization. However, remoting will call OnDeserialization again.
                // We can return immediately if this function is called twice.
                // Note we set remove the serialization info from the table at the end of this method.
                return;
            }

            int realVersion = siInfo.GetInt32(VersionName);
            int hashsize    = siInfo.GetInt32(HashSizeName);

            comparer = (IEqualityComparer <TKey>)siInfo.GetValue(ComparerName, typeof(IEqualityComparer <TKey>));

            if (hashsize != 0)
            {
                buckets = new int[hashsize];
                for (int i = 0; i < buckets.Length; i++)
                {
                    buckets[i] = -1;
                }
                entries  = new Entry[hashsize];
                freeList = -1;

                KeyValuePair <TKey, TValue>[] array = (KeyValuePair <TKey, TValue>[])
                                                      siInfo.GetValue(KeyValuePairsName, typeof(KeyValuePair <TKey, TValue>[]));

                if (array == null)
                {
                    ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingKeys);
                }

                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i].Key == null)
                    {
                        ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_NullKey);
                    }
                    Insert(array[i].Key, array[i].Value, true);
                }
            }
            else
            {
                buckets = null;
            }

            version = realVersion;
            HashHelpers.SerializationInfoTable.Remove(this);
        }
Esempio n. 2
0
 public virtual void OnDeserialization(object sender)
 {
     if (this.m_siInfo != null)
     {
         int num  = this.m_siInfo.GetInt32("Version");
         int num2 = this.m_siInfo.GetInt32("HashSize");
         this.comparer = (IEqualityComparer <TKey>) this.m_siInfo.GetValue("Comparer", typeof(IEqualityComparer <TKey>));
         if (num2 != 0)
         {
             this.buckets = new int[num2];
             for (int i = 0; i < this.buckets.Length; i++)
             {
                 this.buckets[i] = -1;
             }
             this.entries  = new Entry <TKey, TValue> [num2];
             this.freeList = -1;
             KeyValuePair <TKey, TValue>[] pairArray = (KeyValuePair <TKey, TValue>[]) this.m_siInfo.GetValue("KeyValuePairs", typeof(KeyValuePair <TKey, TValue>[]));
             if (pairArray == null)
             {
                 ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingKeyValuePairs);
             }
             for (int j = 0; j < pairArray.Length; j++)
             {
                 if (pairArray[j].Key == null)
                 {
                     ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_NullKey);
                 }
                 this.Insert(pairArray[j].Key, pairArray[j].Value, true);
             }
         }
         else
         {
             this.buckets = null;
         }
         this.version  = num;
         this.m_siInfo = null;
     }
 }
Esempio n. 3
0
        protected void OnDeserialization(Object sender)
        {
            if (comparer != null)
            {
                return; //Somebody had a dependency on this class and fixed us up before the ObjectManager got to it.
            }

            if (siInfo == null)
            {
                ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_InvalidOnDeser);
            }

            comparer = (IComparer <T>)siInfo.GetValue(ComparerName, typeof(IComparer <T>));
            int savedCount = siInfo.GetInt32(CountName);

            if (savedCount != 0)
            {
                T[] items = (T[])siInfo.GetValue(ItemsName, typeof(T[]));

                if (items == null)
                {
                    ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingValues);
                }

                for (int i = 0; i < items.Length; i++)
                {
                    Add(items[i]);
                }
            }

            version = siInfo.GetInt32(VersionName);
            if (count != savedCount)
            {
                ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MismatchedCount);
            }
            siInfo = null;
        }