Exemplo n.º 1
0
        public void TestEnumComparer_Long()
        {
            var comparer = Enum64EqualityComparer.Create <LongEnum>();

            Assert.IsFalse(comparer.Equals(LongEnum.Value1, LongEnum.Value2));
            Assert.IsTrue(comparer.Equals(LongEnum.Value3, LongEnum.Value3));
            Assert.AreEqual((long)LongEnum.Value2.GetHashCode(), comparer.GetHashCode(LongEnum.Value2));
        }
Exemplo n.º 2
0
        private static IEqualityComparer <T> EnumEqualityComparer <T>(Type type)
        {
            switch (Type.GetTypeCode(type))
            {
            case TypeCode.Int64:
            case TypeCode.UInt64:
                return(Enum64EqualityComparer.CreateUnsafe <T>());

            default:
                return(Enum32EqualityComparer.CreateUnsafe <T>());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Registers an equality comparer for type T where T is an enumeration.
        ///     Note: Enumerations are handled automatically and do not need to be registered when JIT is enabled.
        /// </summary>
        public static void RegisterEnum <T>() where T : struct, IConvertible
        {
            var type = typeof(T);

            if (type.IsEnum)
            {
                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Int64:
                case TypeCode.UInt64:
                    Register(Enum64EqualityComparer.Create <T>());
                    break;

                default:
                    Register(Enum32EqualityComparer.Create <T>());
                    break;
                }
            }
            else
            {
                SmoothLogger.LogError("Tried to register a non-enumeration type as an enumeration.");
            }
        }