//
// System.Collections.Comparer.cs
//
-// Author:
-// Sergey Chaban (serge@wildwestsoftware.com)
+// Authors:
+// Sergey Chaban (serge@wildwestsoftware.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
-
-//
-// 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
using System.Globalization;
using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+using System.Security.Permissions;
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
#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 ()
{
if (culture == null)
throw new ArgumentNullException ("culture");
- _culture = culture;
+ m_compareInfo = culture.CompareInfo;
}
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)
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));
}
}
}