Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
OrderedHashtable.cs237 linesDownload Raw Back to engine
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System;5using System.Collections;6using System.Collections.Specialized;7using System.Runtime.Serialization;8 9#nullable enable10 11namespace System.Management.Automation12{13    /// <summary>14    /// OrderedHashtable is a hashtable that preserves the order of the keys.15    /// </summary>16    public sealed class OrderedHashtable : Hashtable, IEnumerable17    {18        private readonly OrderedDictionary _orderedDictionary;19 20        /// <summary>21        /// Initializes a new instance of the <see cref="OrderedHashtable"/> class.22        /// </summary>23        public OrderedHashtable()24        {25            _orderedDictionary = new OrderedDictionary();26        }27 28        /// <summary>29        /// Initializes a new instance of the <see cref="OrderedHashtable"/> class.30        /// </summary>31        /// <param name="capacity">The capacity.</param>32        public OrderedHashtable(int capacity) : base(capacity)33        {34            _orderedDictionary = new OrderedDictionary(capacity);35        }36 37        /// <summary>38        /// Initializes a new instance of the <see cref="OrderedHashtable"/> class.39        /// </summary>40        /// <param name="dictionary">The dictionary to use for initialization.</param>41        public OrderedHashtable(IDictionary dictionary)42        {43            _orderedDictionary = new OrderedDictionary(dictionary.Count);44            foreach (DictionaryEntry entry in dictionary)45            {46                _orderedDictionary.Add(entry.Key, entry.Value);47            }48        }49 50        /// <summary>51        /// Get the number of items in the hashtable.52        /// </summary>53        public override int Count54        {55            get56            {57                return _orderedDictionary.Count;58            }59        }60 61        /// <summary>62        /// Get if the hashtable is a fixed size.63        /// </summary>64        public override bool IsFixedSize65        {66            get67            {68                return false;69            }70        }71 72        /// <summary>73        /// Get if the hashtable is read-only.74        /// </summary>75        public override bool IsReadOnly76        {77            get78            {79                return false;80            }81        }82 83        /// <summary>84        /// Get if the hashtable is synchronized.85        /// </summary>86        public override bool IsSynchronized87        {88            get89            {90                return false;91            }92        }93 94        /// <summary>95        /// Gets the keys in the hashtable.96        /// </summary>97        public override ICollection Keys98        {99            get100            {101                return _orderedDictionary.Keys;102            }103        }104 105        /// <summary>106        /// Gets the values in the hashtable.107        /// </summary>108        public override ICollection Values109        {110            get111            {112                return _orderedDictionary.Values;113            }114        }115 116        /// <summary>117        /// Gets or sets the value associated with the specified key.118        /// </summary>119        /// <param name="key">The key.</param>120        /// <returns>The value associated with the key.</returns>121        public override object? this[object key]122        {123            get124            {125                return _orderedDictionary[key];126            }127 128            set129            {130                _orderedDictionary[key] = value;131            }132        }133 134        /// <summary>135        /// Adds the specified key and value to the hashtable.136        /// </summary>137        /// <param name="key">The key.</param>138        /// <param name="value">The value.</param>139        public override void Add(object key, object? value)140        {141            _orderedDictionary.Add(key, value);142        }143 144        /// <summary>145        /// Removes all keys and values from the hashtable.146        /// </summary>147        public override void Clear()148        {149            _orderedDictionary.Clear();150        }151 152        /// <summary>153        /// Get a shallow clone of the hashtable.154        /// </summary>155        /// <returns>A shallow clone of the hashtable.</returns>156        public override object Clone()157        {158            return new OrderedHashtable(_orderedDictionary);159        }160 161        /// <summary>162        /// Determines whether the hashtable contains a specific key.163        /// </summary>164        /// <param name="key">The key to locate in the hashtable.</param>165        /// <returns>true if the hashtable contains an element with the specified key; otherwise, false.</returns>166        public override bool Contains(object key)167        {168            return _orderedDictionary.Contains(key);169        }170 171        /// <summary>172        /// Determines whether the hashtable contains a specific key.173        /// </summary>174        /// <param name="key">The key to locate in the hashtable.</param>175        /// <returns>true if the hashtable contains an element with the specified key; otherwise, false.</returns>176        public override bool ContainsKey(object key)177        {178            return _orderedDictionary.Contains(key);179        }180 181        /// <summary>182        /// Determines whether the hashtable contains a specific value.183        /// </summary>184        /// <param name="value">The value to locate in the hashtable.</param>185        /// <returns>true if the hashtable contains an element with the specified value; otherwise, false.</returns>186        public override bool ContainsValue(object? value)187        {188            foreach (DictionaryEntry entry in _orderedDictionary)189            {190                if (Equals(entry.Value, value))191                {192                    return true;193                }194            }195 196            return false;197        }198 199        /// <summary>200        /// Copies the elements of the hashtable to an array of type object, starting at the specified array index.201        /// </summary>202        /// <param name="array">The one-dimensional array that is the destination of the elements copied from the hashtable. The array must have zero-based indexing.</param>203        /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>204        public override void CopyTo(Array array, int arrayIndex)205        {206            _orderedDictionary.CopyTo(array, arrayIndex);207        }208 209        /// <summary>210        /// Get the enumerator.211        /// </summary>212        /// <returns>The enumerator.</returns>213        public override IDictionaryEnumerator GetEnumerator()214        {215            return _orderedDictionary.GetEnumerator();216        }217 218        /// <summary>219        /// Get the enumerator.220        /// </summary>221        /// <returns>The enumerator.</returns>222        IEnumerator IEnumerable.GetEnumerator()223        {224            return GetEnumerator();225        }226 227        /// <summary>228        /// Removes the specified key from the hashtable.229        /// </summary>230        /// <param name="key">The key to remove.</param>231        public override void Remove(object key)232        {233            _orderedDictionary.Remove(key);234        }235    }236}237