bring Mono Security to monotouch
[mcs.git] / tests / gtest-197.cs
blobce9cf0884fb6deed07a03ba2ff52defa72bc7a98
1 using System;
2 using System.Runtime.InteropServices;
4 namespace Martin.Collections.Generic {
5 [Serializable]
6 public abstract class EqualityComparer <T> : IEqualityComparer <T> {
8 static EqualityComparer ()
10 if (typeof (IEquatable <T>).IsAssignableFrom (typeof (T)))
11 _default = (EqualityComparer <T>) Activator.CreateInstance (typeof (IEquatableOfTEqualityComparer<>).MakeGenericType (typeof (T)));
12 else
13 _default = new DefaultComparer ();
17 public abstract int GetHashCode (T obj);
18 public abstract bool Equals (T x, T y);
20 static readonly EqualityComparer <T> _default;
22 public static EqualityComparer <T> Default {
23 get {
24 return _default;
28 [Serializable]
29 class DefaultComparer : EqualityComparer<T> {
31 public override int GetHashCode (T obj)
33 return obj.GetHashCode ();
36 public override bool Equals (T x, T y)
38 if (x == null)
39 return y == null;
41 return x.Equals (y);
46 [Serializable]
47 class IEquatableOfTEqualityComparer <T> : EqualityComparer <T> where T : IEquatable <T> {
49 public override int GetHashCode (T obj)
51 return obj.GetHashCode ();
54 public override bool Equals (T x, T y)
56 if (x == null)
57 return y == null;
59 return x.Equals (y);
63 public interface IEqualityComparer<T> {
64 bool Equals (T x, T y);
65 int GetHashCode (T obj);
68 class X
70 static void Main ()
71 { }