SteamVR_EnumEqualityComparer.cs
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Valve.VR
{
struct SteamVREnumEqualityComparer<TEnum> : IEqualityComparer<TEnum> where TEnum : struct
{
static class BoxAvoidance
{
static readonly Func<TEnum, int> _wrapper;
public static int ToInt(TEnum enu)
{
return _wrapper(enu);
}
static BoxAvoidance()
{
var p = Expression.Parameter(typeof(TEnum), null);
var c = Expression.ConvertChecked(p, typeof(int));
_wrapper = Expression.Lambda<Func<TEnum, int>>(c, p).Compile();
}
}
public bool Equals(TEnum firstEnum, TEnum secondEnum)
{
return BoxAvoidance.ToInt(firstEnum) == BoxAvoidance.ToInt(secondEnum);
}
public int GetHashCode(TEnum firstEnum)
{
return BoxAvoidance.ToInt(firstEnum);
}
}
public struct SteamVR_Input_Sources_Comparer : IEqualityComparer<SteamVR_Input_Sources>
{
public bool Equals(SteamVR_Input_Sources x, SteamVR_Input_Sources y)
{
return x == y;
}
public int GetHashCode(SteamVR_Input_Sources obj)
{
return (int)obj;
}
}
}