Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / Collections / Specialized / StringDictionary.cs / 1305376 / StringDictionary.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Collections.Specialized {
using System.Runtime.InteropServices;
using System.Diagnostics;
using System;
using System.Collections;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
///
/// Implements a hashtable with the key strongly typed to be
/// a string rather than an object.
/// Consider this class obsolete - use Dictionary<String, String> instead
/// with a proper StringComparer instance.
///
[Serializable]
[DesignerSerializer("System.Diagnostics.Design.StringDictionaryCodeDomSerializer, " + AssemblyRef.SystemDesign, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + AssemblyRef.SystemDesign)]
// @
public class StringDictionary : IEnumerable {
// For compatibility, we want the Keys property to return values in lower-case.
// That means using ToLower in each property on this type. Also for backwards
// compatibility, we will be converting strings to lower-case, which has a
// problem for some Georgian alphabets. Can't really fix it now though...
internal Hashtable contents = new Hashtable();
///
/// Initializes a new instance of the StringDictionary class.
/// If you're using file names, registry keys, etc, you want to use
/// a Dictionary<String, Object> and use
/// StringComparer.OrdinalIgnoreCase.
///
public StringDictionary() {
}
///
/// Gets the number of key-and-value pairs in the StringDictionary.
///
public virtual int Count {
get {
return contents.Count;
}
}
///
/// Indicates whether access to the StringDictionary is synchronized (thread-safe). This property is
/// read-only.
///
public virtual bool IsSynchronized {
get {
return contents.IsSynchronized;
}
}
///
/// Gets or sets the value associated with the specified key.
///
public virtual string this[string key] {
get {
if( key == null ) {
throw new ArgumentNullException("key");
}
return (string) contents[key.ToLower(CultureInfo.InvariantCulture)];
}
set {
if( key == null ) {
throw new ArgumentNullException("key");
}
contents[key.ToLower(CultureInfo.InvariantCulture)] = value;
}
}
///
/// Gets a collection of keys in the StringDictionary.
///
public virtual ICollection Keys {
get {
return contents.Keys;
}
}
///
/// Gets an object that can be used to synchronize access to the StringDictionary.
///
public virtual object SyncRoot {
get {
return contents.SyncRoot;
}
}
///
/// Gets a collection of values in the StringDictionary.
///
public virtual ICollection Values {
get {
return contents.Values;
}
}
///
/// Adds an entry with the specified key and value into the StringDictionary.
///
public virtual void Add(string key, string value) {
if( key == null ) {
throw new ArgumentNullException("key");
}
contents.Add(key.ToLower(CultureInfo.InvariantCulture), value);
}
///
/// Removes all entries from the StringDictionary.
///
public virtual void Clear() {
contents.Clear();
}
///
/// Determines if the string dictionary contains a specific key
///
public virtual bool ContainsKey(string key) {
if( key == null ) {
throw new ArgumentNullException("key");
}
return contents.ContainsKey(key.ToLower(CultureInfo.InvariantCulture));
}
///
/// Determines if the StringDictionary contains a specific value.
///
public virtual bool ContainsValue(string value) {
return contents.ContainsValue(value);
}
///
/// Copies the string dictionary values to a one-dimensional instance at the
/// specified index.
///
public virtual void CopyTo(Array array, int index) {
contents.CopyTo(array, index);
}
///
/// Returns an enumerator that can iterate through the string dictionary.
///
public virtual IEnumerator GetEnumerator() {
return contents.GetEnumerator();
}
///
/// Removes the entry with the specified key from the string dictionary.
///
public virtual void Remove(string key) {
if( key == null ) {
throw new ArgumentNullException("key");
}
contents.Remove(key.ToLower(CultureInfo.InvariantCulture));
}
///
/// Make this StringDictionary subservient to some other collection.
/// Some code was replacing the contents field with a Hashtable created elsewhere.
/// While it may not have been incorrect, we don't want to encourage that pattern, because
/// it will replace the IEqualityComparer in the Hashtable, and creates a possibly-undesirable
/// link between two seemingly different collections. Let's discourage that somewhat by
/// making this an explicit method call instead of an internal field assignment.
///
/// Replaces the backing store with another, possibly aliased Hashtable.
internal void ReplaceHashtable(Hashtable useThisHashtableInstead) {
contents = useThisHashtableInstead;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Collections.Specialized {
using System.Runtime.InteropServices;
using System.Diagnostics;
using System;
using System.Collections;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
///
/// Implements a hashtable with the key strongly typed to be
/// a string rather than an object.
/// Consider this class obsolete - use Dictionary<String, String> instead
/// with a proper StringComparer instance.
///
[Serializable]
[DesignerSerializer("System.Diagnostics.Design.StringDictionaryCodeDomSerializer, " + AssemblyRef.SystemDesign, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + AssemblyRef.SystemDesign)]
// @
public class StringDictionary : IEnumerable {
// For compatibility, we want the Keys property to return values in lower-case.
// That means using ToLower in each property on this type. Also for backwards
// compatibility, we will be converting strings to lower-case, which has a
// problem for some Georgian alphabets. Can't really fix it now though...
internal Hashtable contents = new Hashtable();
///
/// Initializes a new instance of the StringDictionary class.
/// If you're using file names, registry keys, etc, you want to use
/// a Dictionary<String, Object> and use
/// StringComparer.OrdinalIgnoreCase.
///
public StringDictionary() {
}
///
/// Gets the number of key-and-value pairs in the StringDictionary.
///
public virtual int Count {
get {
return contents.Count;
}
}
///
/// Indicates whether access to the StringDictionary is synchronized (thread-safe). This property is
/// read-only.
///
public virtual bool IsSynchronized {
get {
return contents.IsSynchronized;
}
}
///
/// Gets or sets the value associated with the specified key.
///
public virtual string this[string key] {
get {
if( key == null ) {
throw new ArgumentNullException("key");
}
return (string) contents[key.ToLower(CultureInfo.InvariantCulture)];
}
set {
if( key == null ) {
throw new ArgumentNullException("key");
}
contents[key.ToLower(CultureInfo.InvariantCulture)] = value;
}
}
///
/// Gets a collection of keys in the StringDictionary.
///
public virtual ICollection Keys {
get {
return contents.Keys;
}
}
///
/// Gets an object that can be used to synchronize access to the StringDictionary.
///
public virtual object SyncRoot {
get {
return contents.SyncRoot;
}
}
///
/// Gets a collection of values in the StringDictionary.
///
public virtual ICollection Values {
get {
return contents.Values;
}
}
///
/// Adds an entry with the specified key and value into the StringDictionary.
///
public virtual void Add(string key, string value) {
if( key == null ) {
throw new ArgumentNullException("key");
}
contents.Add(key.ToLower(CultureInfo.InvariantCulture), value);
}
///
/// Removes all entries from the StringDictionary.
///
public virtual void Clear() {
contents.Clear();
}
///
/// Determines if the string dictionary contains a specific key
///
public virtual bool ContainsKey(string key) {
if( key == null ) {
throw new ArgumentNullException("key");
}
return contents.ContainsKey(key.ToLower(CultureInfo.InvariantCulture));
}
///
/// Determines if the StringDictionary contains a specific value.
///
public virtual bool ContainsValue(string value) {
return contents.ContainsValue(value);
}
///
/// Copies the string dictionary values to a one-dimensional instance at the
/// specified index.
///
public virtual void CopyTo(Array array, int index) {
contents.CopyTo(array, index);
}
///
/// Returns an enumerator that can iterate through the string dictionary.
///
public virtual IEnumerator GetEnumerator() {
return contents.GetEnumerator();
}
///
/// Removes the entry with the specified key from the string dictionary.
///
public virtual void Remove(string key) {
if( key == null ) {
throw new ArgumentNullException("key");
}
contents.Remove(key.ToLower(CultureInfo.InvariantCulture));
}
///
/// Make this StringDictionary subservient to some other collection.
/// Some code was replacing the contents field with a Hashtable created elsewhere.
/// While it may not have been incorrect, we don't want to encourage that pattern, because
/// it will replace the IEqualityComparer in the Hashtable, and creates a possibly-undesirable
/// link between two seemingly different collections. Let's discourage that somewhat by
/// making this an explicit method call instead of an internal field assignment.
///
/// Replaces the backing store with another, possibly aliased Hashtable.
internal void ReplaceHashtable(Hashtable useThisHashtableInstead) {
contents = useThisHashtableInstead;
}
}
}
// 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
- ServicePointManager.cs
- _ShellExpression.cs
- TypeHelper.cs
- ToolBarButton.cs
- SmiXetterAccessMap.cs
- SelectionRangeConverter.cs
- AssemblyCacheEntry.cs
- ManualResetEventSlim.cs
- sitestring.cs
- TdsParserSafeHandles.cs
- SubstitutionResponseElement.cs
- XmlSchemaAnnotation.cs
- CalendarDateRange.cs
- InstanceData.cs
- EventLogTraceListener.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- Int64AnimationUsingKeyFrames.cs
- PatternMatcher.cs
- CollectionViewSource.cs
- ContentElement.cs
- DetailsViewPagerRow.cs
- SqlCacheDependencyDatabaseCollection.cs
- GetRecipientListRequest.cs
- Registry.cs
- InputProcessorProfilesLoader.cs
- ButtonColumn.cs
- CancelEventArgs.cs
- PropertyAccessVisitor.cs
- ArraySortHelper.cs
- Point4D.cs
- Identity.cs
- ObjectDataSourceEventArgs.cs
- adornercollection.cs
- TableChangeProcessor.cs
- HostAdapter.cs
- CommandSet.cs
- ProcessingInstructionAction.cs
- HWStack.cs
- SoapExtension.cs
- AbstractDataSvcMapFileLoader.cs
- TableItemProviderWrapper.cs
- ContractAdapter.cs
- PersonalizableAttribute.cs
- InputBinding.cs
- Knowncolors.cs
- ClipboardProcessor.cs
- NameTable.cs
- MulticastOption.cs
- WindowsSpinner.cs
- WebColorConverter.cs
- BaseConfigurationRecord.cs
- Facet.cs
- BitmapFrameEncode.cs
- SelectedCellsCollection.cs
- TypeNameConverter.cs
- XDeferredAxisSource.cs
- TdsParserStaticMethods.cs
- WmlTextBoxAdapter.cs
- ByteFacetDescriptionElement.cs
- UnsafeNativeMethods.cs
- CompareInfo.cs
- CustomErrorsSection.cs
- TcpDuplicateContext.cs
- InkPresenterAutomationPeer.cs
- StringFreezingAttribute.cs
- ItemsPanelTemplate.cs
- Pkcs9Attribute.cs
- BindingWorker.cs
- hebrewshape.cs
- CryptographicAttribute.cs
- FormViewPageEventArgs.cs
- Vector3D.cs
- WorkItem.cs
- CollectionContainer.cs
- PresentationSource.cs
- BevelBitmapEffect.cs
- MenuItemStyleCollection.cs
- RealizationDrawingContextWalker.cs
- QueryOpcode.cs
- Polygon.cs
- WsdlBuildProvider.cs
- DependencyObjectProvider.cs
- StylusPointCollection.cs
- LoadedEvent.cs
- OperationAbortedException.cs
- ModuleBuilderData.cs
- HitTestParameters3D.cs
- DataGridViewDataErrorEventArgs.cs
- SessionConnectionReader.cs
- CodeCastExpression.cs
- UpdateProgress.cs
- ReflectionPermission.cs
- PeerCollaboration.cs
- SmiEventSink.cs
- UnsafeNativeMethods.cs
- GradientStop.cs
- MulticastNotSupportedException.cs
- ComplexTypeEmitter.cs
- DataBindingHandlerAttribute.cs
- ToolStripDropDownDesigner.cs