X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Collections%2FComparer.cs;h=2f2ca54a58586b8f6c42ac3d57184f35b214e591;hb=af90548a08ef5effc93b083b7eec44daa178b141;hp=03f95887428a62943cf9051f7b945d4a9105d0e1;hpb=4a2ab0336e97f3591eebbb881a1471d3051946c9;p=mono.git diff --git a/mcs/class/corlib/System.Collections/Comparer.cs b/mcs/class/corlib/System.Collections/Comparer.cs index 03f95887428..2f2ca54a585 100644 --- a/mcs/class/corlib/System.Collections/Comparer.cs +++ b/mcs/class/corlib/System.Collections/Comparer.cs @@ -1,12 +1,11 @@ // // System.Collections.Comparer.cs // -// Author: -// Sergey Chaban (serge@wildwestsoftware.com) +// Authors: +// Sergey Chaban (serge@wildwestsoftware.com) +// Sebastien Pouliot // - -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -30,6 +29,8 @@ using System.Globalization; using System.Runtime.InteropServices; +using System.Runtime.Serialization; +using System.Security.Permissions; namespace System.Collections { @@ -37,8 +38,8 @@ namespace System.Collections [ComVisible(true)] #endif [Serializable] - public sealed class Comparer : IComparer - { + public sealed class Comparer : IComparer, ISerializable { + public static readonly Comparer Default = new Comparer (); #if NET_1_1 public @@ -47,7 +48,8 @@ namespace System.Collections #endif static readonly Comparer DefaultInvariant = new Comparer (CultureInfo.InvariantCulture); - CultureInfo _culture; + // This field was introduced for MS kompatibility. see bug #77701 + CompareInfo m_compareInfo; private Comparer () { @@ -64,7 +66,7 @@ namespace System.Collections if (culture == null) throw new ArgumentNullException ("culture"); - _culture = culture; + m_compareInfo = culture.CompareInfo; } @@ -78,11 +80,11 @@ namespace System.Collections else if (b == null) return 1; - if (_culture != null) { + if (m_compareInfo != null) { string sa = a as string; string sb = b as string; if (sa != null && sb != null) - return _culture.CompareInfo.Compare (sa, sb); + return m_compareInfo.Compare (sa, sb); } if (a is IComparable) @@ -90,7 +92,17 @@ namespace System.Collections else if (b is IComparable) return -(b as IComparable).CompareTo (a); - throw new ArgumentException (Locale.GetText ("Neither a nor b Comparable.")); + throw new ArgumentException (Locale.GetText ("Neither 'a' nor 'b' implements IComparable.")); + } + + // ISerializable + [SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)] + public void GetObjectData (SerializationInfo info, StreamingContext context) + { + if (info == null) + throw new ArgumentNullException ("info"); + + info.AddValue ("CompareInfo", m_compareInfo, typeof (CompareInfo)); } } }