Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Collections / CaseInsensitiveComparer.cs / 1 / CaseInsensitiveComparer.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: CaseInsensitiveComparer
**
**
**
============================================================*/
namespace System.Collections {
//This class does not contain members and does not need to be serializable
using System;
using System.Collections;
using System.Globalization;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class CaseInsensitiveComparer : IComparer {
private CompareInfo m_compareInfo;
private static CaseInsensitiveComparer m_InvariantCaseInsensitiveComparer;
public CaseInsensitiveComparer() {
m_compareInfo = CultureInfo.CurrentCulture.CompareInfo;
}
public CaseInsensitiveComparer(CultureInfo culture) {
if (culture==null) {
throw new ArgumentNullException("culture");
}
m_compareInfo = culture.CompareInfo;
}
public static CaseInsensitiveComparer Default
{
get
{
return new CaseInsensitiveComparer(CultureInfo.CurrentCulture);
}
}
public static CaseInsensitiveComparer DefaultInvariant
{
get
{
if (m_InvariantCaseInsensitiveComparer == null) {
m_InvariantCaseInsensitiveComparer = new CaseInsensitiveComparer(CultureInfo.InvariantCulture);
}
return m_InvariantCaseInsensitiveComparer;
}
}
// Behaves exactly like Comparer.Default.Compare except that the comparison is case insensitive
// Compares two Objects by calling CompareTo. If a ==
// b,0 is returned. If a implements
// IComparable, a.CompareTo(b) is returned. If a
// doesn't implement IComparable and b does,
// -(b.CompareTo(a)) is returned, otherwise an
// exception is thrown.
//
public int Compare(Object a, Object b) {
String sa = a as String;
String sb = b as String;
if (sa != null && sb != null)
return m_compareInfo.Compare(sa, sb, CompareOptions.IgnoreCase);
else
return Comparer.Default.Compare(a,b);
}
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SoapAttributeAttribute.cs
- TextParagraphView.cs
- CheckoutException.cs
- Parser.cs
- XhtmlBasicFormAdapter.cs
- SiteMapProvider.cs
- BitmapEffectRenderDataResource.cs
- RegisteredArrayDeclaration.cs
- CodeArrayIndexerExpression.cs
- StreamingContext.cs
- DataKeyCollection.cs
- basevalidator.cs
- FactoryGenerator.cs
- QueryExtender.cs
- MexServiceChannelBuilder.cs
- ProviderBase.cs
- DataSourceExpressionCollection.cs
- WsdlInspector.cs
- DefinitionUpdate.cs
- PrintPreviewGraphics.cs
- HandlerWithFactory.cs
- PropertyInfoSet.cs
- EventItfInfo.cs
- UiaCoreApi.cs
- AutomationIdentifierGuids.cs
- FormsAuthenticationConfiguration.cs
- DeflateEmulationStream.cs
- FieldNameLookup.cs
- Storyboard.cs
- VectorConverter.cs
- ReadOnlyTernaryTree.cs
- FamilyMapCollection.cs
- TemplateInstanceAttribute.cs
- TextTreeTextBlock.cs
- RawAppCommandInputReport.cs
- ObjectDataSourceEventArgs.cs
- LinkArea.cs
- BasicCommandTreeVisitor.cs
- WebConfigurationHostFileChange.cs
- DataFormats.cs
- BaseTemplateParser.cs
- DecoderBestFitFallback.cs
- ModuleElement.cs
- DataGridRowAutomationPeer.cs
- ToolStripScrollButton.cs
- BrowserTree.cs
- ImportStoreException.cs
- Matrix3D.cs
- CompilerScope.Storage.cs
- SafeFileMappingHandle.cs
- SqlDependencyListener.cs
- RelatedView.cs
- LayoutExceptionEventArgs.cs
- CorrelationTokenInvalidatedHandler.cs
- ProxyWebPart.cs
- EndPoint.cs
- InstanceData.cs
- ProviderConnectionPoint.cs
- BindingBase.cs
- ProgressBarAutomationPeer.cs
- ApplicationId.cs
- FrameDimension.cs
- GraphicsPath.cs
- WebPartRestoreVerb.cs
- IndexedString.cs
- SqlTriggerAttribute.cs
- TrustLevelCollection.cs
- QueryLifecycle.cs
- RichTextBoxConstants.cs
- EmissiveMaterial.cs
- SchemaLookupTable.cs
- CharEnumerator.cs
- DataGridLengthConverter.cs
- PasswordPropertyTextAttribute.cs
- ComboBox.cs
- NoClickablePointException.cs
- IncrementalReadDecoders.cs
- DefaultBinder.cs
- XmlBinaryReaderSession.cs
- XslVisitor.cs
- ChildrenQuery.cs
- LineServices.cs
- QueryExpr.cs
- SmiRequestExecutor.cs
- ToolStripDropDownButton.cs
- TranslateTransform.cs
- StringSource.cs
- IntSecurity.cs
- RelationalExpressions.cs
- SqlRecordBuffer.cs
- StateChangeEvent.cs
- ReadOnlyCollectionBase.cs
- DragDrop.cs
- RuntimeComponentFilter.cs
- SessionPageStatePersister.cs
- ProxyAttribute.cs
- DataControlFieldHeaderCell.cs
- ContainerSelectorGlyph.cs
- TemplateLookupAction.cs
- SqlExpressionNullability.cs