CaseInsensitiveOrdinalStringComparer.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Base / MS / Internal / IO / Packaging / CaseInsensitiveOrdinalStringComparer.cs / 1 / CaseInsensitiveOrdinalStringComparer.cs

                            //------------------------------------------------------------------------------ 
//
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved.
//  
//
// Description: 
//  Common container-related operations that can be shared among internal 
//  components.
// 
// History:
//  02/17/2006: [....]: Creation
//
//----------------------------------------------------------------------------- 

using System; 
using System.Collections;   // for IEqualityComparer 

using MS.Internal;          // for Invariant.Assert 

namespace MS.Internal.IO.Packaging
{
    ///  
    /// IEqualityComparer implementation for case insensistive ordinal strings
    ///  
    internal class CaseInsensitiveOrdinalStringComparer : 
                                IEqualityComparer, IComparer
    { 
        // Performs Case Insensitive Ordinal String Comparison.
        bool IEqualityComparer.Equals(Object x, Object y)
        {
            Invariant.Assert((x is String) && (y is String)); 
            return (String.CompareOrdinal(((String) x).ToUpperInvariant(),
                                ((String) y).ToUpperInvariant()) == 0); 
        } 

        int IComparer.Compare(Object x, Object y) 
        {
            Invariant.Assert((x is String) && (y is String));

            return String.CompareOrdinal(((String) x).ToUpperInvariant(), 
                                ((String) y).ToUpperInvariant());
        } 
 
        // Hash on object identity.
        int IEqualityComparer.GetHashCode(Object str) 
        {
            Invariant.Assert(str is String);

            return ((String) str).ToUpperInvariant().GetHashCode(); 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK