Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / System.Runtime.DurableInstancing / System / Runtime / Collections / OrderedDictionary.cs / 1305376 / OrderedDictionary.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Collections
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
// System.Collections.Specialized.OrderedDictionary is NOT generic.
// This class is essentially a generic wrapper for OrderedDictionary.
class OrderedDictionary : IDictionary, ICollection>, IEnumerable>
{
OrderedDictionary privateDictionary;
public OrderedDictionary()
{
this.privateDictionary = new OrderedDictionary();
}
public OrderedDictionary(IDictionary dictionary)
{
if (dictionary != null)
{
this.privateDictionary = new OrderedDictionary();
foreach (KeyValuePair pair in dictionary)
{
this.privateDictionary.Add(pair.Key, pair.Value);
}
}
}
public int Count
{
get
{
return this.privateDictionary.Count;
}
}
public bool IsReadOnly
{
get
{
return false;
}
}
public TValue this[TKey key]
{
get
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
if (this.privateDictionary.Contains(key))
{
return (TValue)this.privateDictionary[(object)key];
}
else
{
throw Fx.Exception.AsError(new KeyNotFoundException(SRCore.KeyNotFoundInDictionary));
}
}
set
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
this.privateDictionary[(object)key] = value;
}
}
public ICollection Keys
{
get
{
List keys = new List(this.privateDictionary.Count);
foreach (TKey key in this.privateDictionary.Keys)
{
keys.Add(key);
}
// Keys should be put in a ReadOnlyCollection,
// but since this is an internal class, for performance reasons,
// we choose to avoid creating yet another collection.
return keys;
}
}
public ICollection Values
{
get
{
List values = new List(this.privateDictionary.Count);
foreach (TValue value in this.privateDictionary.Values)
{
values.Add(value);
}
// Values should be put in a ReadOnlyCollection,
// but since this is an internal class, for performance reasons,
// we choose to avoid creating yet another collection.
return values;
}
}
public void Add(KeyValuePair item)
{
Add(item.Key, item.Value);
}
public void Add(TKey key, TValue value)
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
this.privateDictionary.Add(key, value);
}
public void Clear()
{
this.privateDictionary.Clear();
}
public bool Contains(KeyValuePair item)
{
if (item.Key == null || !this.privateDictionary.Contains(item.Key))
{
return false;
}
else
{
return this.privateDictionary[(object)item.Key].Equals(item.Value);
}
}
public bool ContainsKey(TKey key)
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
return this.privateDictionary.Contains(key);
}
public void CopyTo(KeyValuePair[] array, int arrayIndex)
{
if (array == null)
{
throw Fx.Exception.ArgumentNull("array");
}
if (arrayIndex < 0)
{
throw Fx.Exception.AsError(new ArgumentOutOfRangeException("arrayIndex"));
}
if (array.Rank > 1 || arrayIndex >= array.Length || array.Length - arrayIndex < this.privateDictionary.Count)
{
throw Fx.Exception.Argument("array", SRCore.BadCopyToArray);
}
int index = arrayIndex;
foreach (DictionaryEntry entry in this.privateDictionary)
{
array[index] = new KeyValuePair((TKey)entry.Key, (TValue)entry.Value);
index++;
}
}
public IEnumerator> GetEnumerator()
{
foreach (DictionaryEntry entry in this.privateDictionary)
{
yield return new KeyValuePair((TKey)entry.Key, (TValue)entry.Value);
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool Remove(KeyValuePair item)
{
if (Contains(item))
{
this.privateDictionary.Remove(item.Key);
return true;
}
else
{
return false;
}
}
public bool Remove(TKey key)
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
if (this.privateDictionary.Contains(key))
{
this.privateDictionary.Remove(key);
return true;
}
else
{
return false;
}
}
public bool TryGetValue(TKey key, out TValue value)
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
bool keyExists = this.privateDictionary.Contains(key);
value = keyExists ? (TValue)this.privateDictionary[(object)key] : default(TValue);
return keyExists;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Collections
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
// System.Collections.Specialized.OrderedDictionary is NOT generic.
// This class is essentially a generic wrapper for OrderedDictionary.
class OrderedDictionary : IDictionary, ICollection>, IEnumerable>
{
OrderedDictionary privateDictionary;
public OrderedDictionary()
{
this.privateDictionary = new OrderedDictionary();
}
public OrderedDictionary(IDictionary dictionary)
{
if (dictionary != null)
{
this.privateDictionary = new OrderedDictionary();
foreach (KeyValuePair pair in dictionary)
{
this.privateDictionary.Add(pair.Key, pair.Value);
}
}
}
public int Count
{
get
{
return this.privateDictionary.Count;
}
}
public bool IsReadOnly
{
get
{
return false;
}
}
public TValue this[TKey key]
{
get
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
if (this.privateDictionary.Contains(key))
{
return (TValue)this.privateDictionary[(object)key];
}
else
{
throw Fx.Exception.AsError(new KeyNotFoundException(SRCore.KeyNotFoundInDictionary));
}
}
set
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
this.privateDictionary[(object)key] = value;
}
}
public ICollection Keys
{
get
{
List keys = new List(this.privateDictionary.Count);
foreach (TKey key in this.privateDictionary.Keys)
{
keys.Add(key);
}
// Keys should be put in a ReadOnlyCollection,
// but since this is an internal class, for performance reasons,
// we choose to avoid creating yet another collection.
return keys;
}
}
public ICollection Values
{
get
{
List values = new List(this.privateDictionary.Count);
foreach (TValue value in this.privateDictionary.Values)
{
values.Add(value);
}
// Values should be put in a ReadOnlyCollection,
// but since this is an internal class, for performance reasons,
// we choose to avoid creating yet another collection.
return values;
}
}
public void Add(KeyValuePair item)
{
Add(item.Key, item.Value);
}
public void Add(TKey key, TValue value)
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
this.privateDictionary.Add(key, value);
}
public void Clear()
{
this.privateDictionary.Clear();
}
public bool Contains(KeyValuePair item)
{
if (item.Key == null || !this.privateDictionary.Contains(item.Key))
{
return false;
}
else
{
return this.privateDictionary[(object)item.Key].Equals(item.Value);
}
}
public bool ContainsKey(TKey key)
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
return this.privateDictionary.Contains(key);
}
public void CopyTo(KeyValuePair[] array, int arrayIndex)
{
if (array == null)
{
throw Fx.Exception.ArgumentNull("array");
}
if (arrayIndex < 0)
{
throw Fx.Exception.AsError(new ArgumentOutOfRangeException("arrayIndex"));
}
if (array.Rank > 1 || arrayIndex >= array.Length || array.Length - arrayIndex < this.privateDictionary.Count)
{
throw Fx.Exception.Argument("array", SRCore.BadCopyToArray);
}
int index = arrayIndex;
foreach (DictionaryEntry entry in this.privateDictionary)
{
array[index] = new KeyValuePair((TKey)entry.Key, (TValue)entry.Value);
index++;
}
}
public IEnumerator> GetEnumerator()
{
foreach (DictionaryEntry entry in this.privateDictionary)
{
yield return new KeyValuePair((TKey)entry.Key, (TValue)entry.Value);
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool Remove(KeyValuePair item)
{
if (Contains(item))
{
this.privateDictionary.Remove(item.Key);
return true;
}
else
{
return false;
}
}
public bool Remove(TKey key)
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
if (this.privateDictionary.Contains(key))
{
this.privateDictionary.Remove(key);
return true;
}
else
{
return false;
}
}
public bool TryGetValue(TKey key, out TValue value)
{
if (key == null)
{
throw Fx.Exception.ArgumentNull("key");
}
bool keyExists = this.privateDictionary.Contains(key);
value = keyExists ? (TValue)this.privateDictionary[(object)key] : default(TValue);
return keyExists;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StringHelper.cs
- ActivityExecutorOperation.cs
- TitleStyle.cs
- TextEditorMouse.cs
- QueryResponse.cs
- Condition.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- IncomingWebResponseContext.cs
- TrackingRecord.cs
- LocalFileSettingsProvider.cs
- ToolStripDropDownItem.cs
- LocationUpdates.cs
- DetailsViewModeEventArgs.cs
- AssociationSet.cs
- TextElement.cs
- WebPartCollection.cs
- VarInfo.cs
- BitmapEffect.cs
- Validator.cs
- ItemsControlAutomationPeer.cs
- ParameterToken.cs
- DynamicEndpoint.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- ClipboardProcessor.cs
- SchemaMapping.cs
- SetIterators.cs
- TraceContextEventArgs.cs
- FamilyTypefaceCollection.cs
- TextAdaptor.cs
- TypeDescriptor.cs
- SqlTransaction.cs
- BindingFormattingDialog.cs
- VectorAnimation.cs
- IMembershipProvider.cs
- PropertyMetadata.cs
- StylusTip.cs
- WebCategoryAttribute.cs
- NameTable.cs
- PtsContext.cs
- ControlPropertyNameConverter.cs
- TabletCollection.cs
- ExpressionNormalizer.cs
- IdentifierService.cs
- BrowserDefinition.cs
- LinkButton.cs
- PointLight.cs
- InternalDispatchObject.cs
- CellParagraph.cs
- DbConnectionPoolOptions.cs
- DataPagerField.cs
- CapabilitiesUse.cs
- WebScriptEnablingBehavior.cs
- SignatureHelper.cs
- TextContainerHelper.cs
- FrugalMap.cs
- ThrowHelper.cs
- MetadataCollection.cs
- CheckBoxField.cs
- DataStorage.cs
- Imaging.cs
- DiscardableAttribute.cs
- TreeNode.cs
- StylusPoint.cs
- CharKeyFrameCollection.cs
- SocketSettings.cs
- SizeLimitedCache.cs
- NumericUpDownAccelerationCollection.cs
- InfoCardSymmetricAlgorithm.cs
- InputLanguageEventArgs.cs
- DashStyle.cs
- ListenerTraceUtility.cs
- configsystem.cs
- PerfCounters.cs
- ObjectDataSourceEventArgs.cs
- TextEditorCopyPaste.cs
- RootBuilder.cs
- OdbcInfoMessageEvent.cs
- WriteLineDesigner.xaml.cs
- ButtonBase.cs
- AmbiguousMatchException.cs
- xsdvalidator.cs
- RegexStringValidatorAttribute.cs
- Tuple.cs
- Cursors.cs
- HtmlElementEventArgs.cs
- MetaData.cs
- UITypeEditor.cs
- PerfCounters.cs
- Stacktrace.cs
- ManagementEventWatcher.cs
- XmlSubtreeReader.cs
- ManageRequest.cs
- TransactionsSectionGroup.cs
- SqlDeflator.cs
- ReflectionUtil.cs
- DynamicVirtualDiscoSearcher.cs
- XmlQuerySequence.cs
- RelatedPropertyManager.cs
- MemoryRecordBuffer.cs
- XmlSchemaSimpleContentRestriction.cs