Exemplo n.º 1
0
        public void Adjust(Collection.Node Node, ForEachEnum.AdjustIndexType Type)
        {
            if (Node == null || this.mDisposed)
            {
                return;
            }
            switch (Type)
            {
            case ForEachEnum.AdjustIndexType.Insert:
                if (this.mCurrent == null || Node != this.mCurrent.m_Next)
                {
                    break;
                }
                this.mNext = Node;
                break;

            case ForEachEnum.AdjustIndexType.Remove:
                if (Node == this.mCurrent || Node != this.mNext)
                {
                    break;
                }
                this.mNext = this.mNext.m_Next;
                break;
            }
        }
Exemplo n.º 2
0
 public bool MoveNext()
 {
     if (this.mDisposed)
     {
         return(false);
     }
     if (this.mAtBeginning)
     {
         this.mAtBeginning = false;
         this.mNext        = this.mCollectionObject.GetFirstListNode();
     }
     if (this.mNext == null)
     {
         ((IDisposable)this).Dispose();
         return(false);
     }
     this.mCurrent = this.mNext;
     if (this.mCurrent != null)
     {
         this.mNext = this.mCurrent.m_Next;
         return(true);
     }
     ((IDisposable)this).Dispose();
     return(false);
 }
Exemplo n.º 3
0
 void IDisposable.Dispose()
 {
     if (!this.mDisposed)
     {
         this.mCollectionObject.RemoveIterator(this.WeakRef);
         this.mDisposed = true;
     }
     this.mCurrent = (Collection.Node)null;
     this.mNext    = (Collection.Node)null;
 }
Exemplo n.º 4
0
 public void Reset()
 {
     if (this.mDisposed)
     {
         this.mCollectionObject.AddIterator(this.WeakRef);
         this.mDisposed = false;
     }
     this.mCurrent     = (Collection.Node)null;
     this.mNext        = (Collection.Node)null;
     this.mAtBeginning = true;
 }
Exemplo n.º 5
0
 void IList.RemoveAt(int index)
 {
     Collection.Node RemovedNode = this.m_ItemsList.RemoveAt(index);
     this.AdjustEnumeratorsOnNodeRemoved(RemovedNode);
     if (RemovedNode.m_Key != null)
     {
         this.m_KeyedNodesHash.Remove(RemovedNode.m_Key);
     }
     RemovedNode.m_Prev = (Collection.Node)null;
     RemovedNode.m_Next = (Collection.Node)null;
 }
Exemplo n.º 6
0
 /// <summary>Removes an element from a <see langword="Collection" /> object.</summary>
 /// <param name="Index">A numeric expression that specifies the position of an element of the collection. <paramref name="Index" /> must be a number from 1 through the value of the collection's <see cref="P:Ported.VisualBasic.Collection.Count" /> property.</param>
 public void Remove(int Index)
 {
     this.IndexCheck(Index);
     Collection.Node RemovedNode = this.m_ItemsList.RemoveAt(checked (Index - 1));
     this.AdjustEnumeratorsOnNodeRemoved(RemovedNode);
     if (RemovedNode.m_Key != null)
     {
         this.m_KeyedNodesHash.Remove(RemovedNode.m_Key);
     }
     RemovedNode.m_Prev = (Collection.Node)null;
     RemovedNode.m_Next = (Collection.Node)null;
 }
Exemplo n.º 7
0
 internal void Add(Collection.Node Node)
 {
     if (this.m_StartOfList == null)
     {
         this.m_StartOfList = Node;
     }
     else
     {
         this.m_EndOfList.m_Next = Node;
         Node.m_Prev             = this.m_EndOfList;
     }
     this.m_EndOfList = Node;
     checked { ++this.m_Count; }
 }
Exemplo n.º 8
0
            internal int IndexOfValue(object Value)
            {
                Collection.Node node = this.m_StartOfList;
                int             num  = 0;

                while (node != null)
                {
                    if (this.DataIsEqual(node.m_Value, Value))
                    {
                        return(num);
                    }
                    node = node.m_Next;
                    checked { ++num; }
                }
                return(-1);
            }
Exemplo n.º 9
0
        private void AdjustEnumeratorsHelper(Collection.Node NewOrRemovedNode, ForEachEnum.AdjustIndexType Type)
        {
            int index = checked (this.m_Iterators.Count - 1);

            while (index >= 0)
            {
                WeakReference iterator = (WeakReference)this.m_Iterators[index];
                if (iterator.IsAlive)
                {
                    ((ForEachEnum)iterator.Target)?.Adjust(NewOrRemovedNode, Type);
                }
                else
                {
                    this.m_Iterators.RemoveAt(index);
                }
                checked { --index; }
            }
        }
Exemplo n.º 10
0
 /// <summary>Returns a specific element of a <see langword="Collection" /> object either by position or by key. Read-only.</summary>
 /// <param name="Key">A unique <see langword="String" /> expression that specifies a key string that can be used, instead of a positional index, to access an element of the collection. <paramref name="Key" /> must correspond to the <paramref name="Key" /> argument specified when the element was added to the collection.</param>
 /// <returns>Returns a specific element of a <see langword="Collection" /> object either by position or by key. Read-only.</returns>
 public object this[string Key]
 {
     get
     {
         if (Key == null)
         {
             throw new IndexOutOfRangeException(Utils.GetResourceString("Argument_CollectionIndex"));
         }
         Collection.Node node = (Collection.Node)null;
         if (!this.m_KeyedNodesHash.TryGetValue(Key, out node))
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[1]
             {
                 "Index"
             }));
         }
         return(node.m_Value);
     }
 }
Exemplo n.º 11
0
 /// <summary>Removes an element from a <see langword="Collection" /> object.</summary>
 /// <param name="Key">A unique <see langword="String" /> expression that specifies a key string that can be used, instead of a positional index, to access an element of the collection. <paramref name="Key" /> must correspond to the <paramref name="Key" /> argument specified when the element was added to the collection.</param>
 public void Remove(string Key)
 {
     Collection.Node node = (Collection.Node)null;
     if (this.m_KeyedNodesHash.TryGetValue(Key, out node))
     {
         this.AdjustEnumeratorsOnNodeRemoved(node);
         this.m_KeyedNodesHash.Remove(Key);
         this.m_ItemsList.RemoveNode(node);
         node.m_Prev = (Collection.Node)null;
         node.m_Next = (Collection.Node)null;
     }
     else
     {
         throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[1]
         {
             nameof(Key)
         }));
     }
 }
Exemplo n.º 12
0
            internal Collection.Node RemoveAt(int Index)
            {
                Collection.Node NodeToBeDeleted = this.m_StartOfList;
                int             num             = 0;

                Collection.Node PrevNode = (Collection.Node)null;
                while (num < Index && NodeToBeDeleted != null)
                {
                    PrevNode        = NodeToBeDeleted;
                    NodeToBeDeleted = NodeToBeDeleted.m_Next;
                    checked { ++num; }
                }
                if (NodeToBeDeleted == null)
                {
                    throw new ArgumentOutOfRangeException(nameof(Index));
                }
                this.DeleteNode(NodeToBeDeleted, PrevNode);
                return(NodeToBeDeleted);
            }
Exemplo n.º 13
0
        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            string[]        strArray = new string[checked (this.Count - 1 + 1)];
            object[]        objArray = new object[checked (this.Count - 1 + 1)];
            Collection.Node node     = this.GetFirstListNode();
            int             num      = 0;

            for (; node != null; node = node.m_Next)
            {
                if (node.m_Key != null)
                {
                    checked { ++num; }
                }
                int index = 0;
                strArray[index] = node.m_Key;
                objArray[index] = node.m_Value;
                checked { ++index; }
            }
            info.AddValue("Keys", (object)strArray, typeof(string[]));
            info.AddValue("KeysCount", (object)num, typeof(int));
            info.AddValue("Values", (object)objArray, typeof(object[]));
            info.AddValue("CultureInfo", (object)this.m_CultureInfo);
        }
Exemplo n.º 14
0
 private void AdjustEnumeratorsOnNodeRemoved(Collection.Node RemovedNode)
 {
     this.AdjustEnumeratorsHelper(RemovedNode, ForEachEnum.AdjustIndexType.Remove);
 }
Exemplo n.º 15
0
 internal void RemoveNode(Collection.Node NodeToBeDeleted)
 {
     this.DeleteNode(NodeToBeDeleted, NodeToBeDeleted.m_Prev);
 }
Exemplo n.º 16
0
 private void AdjustEnumeratorsOnNodeInserted(Collection.Node NewNode)
 {
     this.AdjustEnumeratorsHelper(NewNode, ForEachEnum.AdjustIndexType.Insert);
 }
Exemplo n.º 17
0
 internal void Clear()
 {
     this.m_StartOfList = (Collection.Node)null;
     this.m_EndOfList   = (Collection.Node)null;
     this.m_Count       = 0;
 }
Exemplo n.º 18
0
 void IList.Insert(int index, object value)
 {
     Collection.Node node = new Collection.Node((string)null, value);
     this.m_ItemsList.Insert(index, node);
     this.AdjustEnumeratorsOnNodeInserted(node);
 }
Exemplo n.º 19
0
 /// <summary>Adds an element to a <see langword="Collection" /> object.</summary>
 /// <param name="Item">Required. An object of any type that specifies the element to add to the collection.</param>
 /// <param name="Key">Optional. A unique <see langword="String" /> expression that specifies a key string that can be used instead of a positional index to access this new element in the collection.</param>
 /// <param name="Before">Optional. An expression that specifies a relative position in the collection. The element to be added is placed in the collection before the element identified by the <paramref name="Before" /> argument. If <paramref name="Before" /> is a numeric expression, it must be a number from 1 through the value of the collection's <see cref="P:Ported.VisualBasic.Collection.Count" /> property. If <paramref name="Before" /> is a <see langword="String" /> expression, it must correspond to the key string specified when the element being referred to was added to the collection. You cannot specify both <paramref name="Before" /> and <paramref name="After" />.</param>
 /// <param name="After">Optional. An expression that specifies a relative position in the collection. The element to be added is placed in the collection after the element identified by the <paramref name="After" /> argument. If <paramref name="After" /> is a numeric expression, it must be a number from 1 through the value of the collection's <see langword="Count" /> property. If <paramref name="After" /> is a <see langword="String" /> expression, it must correspond to the key string specified when the element referred to was added to the collection. You cannot specify both <paramref name="Before" /> and <paramref name="After" />.</param>
 public void Add(object Item, string Key = null, object Before = null, object After = null)
 {
     if (Before != null && After != null)
     {
         throw new ArgumentException(Utils.GetResourceString("Collection_BeforeAfterExclusive"));
     }
     Collection.Node node = new Collection.Node(Key, Item);
     if (Key != null)
     {
         try
         {
             this.m_KeyedNodesHash.Add(Key, node);
         }
         catch (ArgumentException ex)
         {
             throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Collection_DuplicateKey")), 457);
         }
     }
     try
     {
         if (Before == null && After == null)
         {
             this.m_ItemsList.Add(node);
         }
         else if (Before != null)
         {
             string key = Before as string;
             if (key != null)
             {
                 Collection.Node NodeToInsertBefore = (Collection.Node)null;
                 if (!this.m_KeyedNodesHash.TryGetValue(key, out NodeToInsertBefore))
                 {
                     throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[1]
                     {
                         nameof(Before)
                     }));
                 }
                 this.m_ItemsList.InsertBefore(node, NodeToInsertBefore);
             }
             else
             {
                 this.m_ItemsList.Insert(checked (Conversions.ToInteger(Before) - 1), node);
             }
         }
         else
         {
             string key = After as string;
             if (key != null)
             {
                 Collection.Node NodeToInsertAfter = (Collection.Node)null;
                 if (!this.m_KeyedNodesHash.TryGetValue(key, out NodeToInsertAfter))
                 {
                     throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[1]
                     {
                         nameof(After)
                     }));
                 }
                 this.m_ItemsList.InsertAfter(node, NodeToInsertAfter);
             }
             else
             {
                 this.m_ItemsList.Insert(Conversions.ToInteger(After), node);
             }
         }
     }
     catch (OutOfMemoryException ex)
     {
         throw;
     }
     catch (ThreadAbortException ex)
     {
         throw;
     }
     catch (StackOverflowException ex)
     {
         throw;
     }
     catch (Exception ex)
     {
         if (Key != null)
         {
             this.m_KeyedNodesHash.Remove(Key);
         }
         throw;
     }
     this.AdjustEnumeratorsOnNodeInserted(node);
 }
Exemplo n.º 20
0
            internal Collection.Node get_Item(int Index)
            {
                int Index1 = Index;

                Collection.Node     node  = (Collection.Node)null;
                ref Collection.Node local = ref node;
Exemplo n.º 21
0
 internal void AdjustOnListCleared()
 {
     this.mNext = (Collection.Node)null;
 }