The Labs \ Source Viewer \ SSCLI \ System \ InvariantComparer

  1. //------------------------------------------------------------------------------
  2. // <copyright file="InvariantComparer.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System
  16. {
  17.     using System;
  18.     using System.Collections;
  19.     using System.Globalization;
  20.    
  21.     [Serializable()]
  22.     internal class InvariantComparer : IComparer
  23.     {
  24.         private CompareInfo m_compareInfo;
  25.         static internal readonly InvariantComparer Default = new InvariantComparer();
  26.        
  27.         internal InvariantComparer()
  28.         {
  29.             m_compareInfo = CultureInfo.InvariantCulture.CompareInfo;
  30.         }
  31.        
  32.         public int Compare(object a, object b)
  33.         {
  34.             string sa = a as string;
  35.             string sb = b as string;
  36.             if (sa != null && sb != null)
  37.                 return m_compareInfo.Compare(sa, sb);
  38.             else
  39.                 return Comparer.Default.Compare(a, b);
  40.         }
  41.     }
  42. }

Developer Fusion