Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AnonymousEqualityComparer.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 
6 namespace SiliconStudio.Presentation.Core
7 {
8  /// <summary>
9  /// This class allows implementation of <see cref="IEqualityComparer{T}"/> using anonymous functions.
10  /// </summary>
11  /// <typeparam name="T">The type of object this comparer can compare.</typeparam>
12  public class AnonymousEqualityComparer<T> : IEqualityComparer<T>
13  {
14  private readonly Func<T, T, bool> equals;
15  private readonly Func<T, int> getHashCode;
16 
17  /// <summary>
18  /// Initializes a new instance of the <see cref="AnonymousEqualityComparer{T}"/> class.
19  /// </summary>
20  /// <param name="equals">The equality function to use for this equality comparer.</param>
21  /// <param name="getHashCode">The function to use to compute hash codes for the objects to compare.</param>
22  public AnonymousEqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode)
23  {
24  if (equals == null) throw new ArgumentNullException("equals");
25  if (getHashCode == null) throw new ArgumentNullException("getHashCode");
26  this.equals = equals;
27  this.getHashCode = getHashCode;
28  }
29 
30  /// <summary>
31  /// Initializes a new instance of the <see cref="AnonymousEqualityComparer{T}"/> class using the default <see cref="object.GetHashCode"/> method to get hash codes.
32  /// </summary>
33  /// <param name="equals">The equality function to use for this equality comparer.</param>
34  public AnonymousEqualityComparer(Func<T, T, bool> equals)
35  : this(equals, obj => obj.GetHashCode())
36  {
37  }
38 
39  /// <inheritdoc/>
40  public bool Equals(T x, T y)
41  {
42  return equals(x, y);
43  }
44 
45  /// <inheritdoc/>
46  public int GetHashCode(T obj)
47  {
48  return getHashCode(obj);
49  }
50  }
51 }
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
AnonymousEqualityComparer(Func< T, T, bool > equals, Func< T, int > getHashCode)
Initializes a new instance of the AnonymousEqualityComparer{T} class.
AnonymousEqualityComparer(Func< T, T, bool > equals)
Initializes a new instance of the AnonymousEqualityComparer{T} class using the default object...