internal static object GetBuiltinComparer
#if !UNITY
        <T>
#endif
        (Type t)
        {
            object comparer = null;

            if (t == typeof(Int16))
            {
                comparer = new Int16EqualityComparer();
            }
            else if (t == typeof(Int32))
            {
                comparer = new Int32EqualityComparer();
            }
            else if (t == typeof(Int64))
            {
                comparer = new Int64EqualityComparer();
            }
            else if (t == typeof(UInt16))
            {
                comparer = new UInt16EqualityComparer();
            }
            else if (t == typeof(UInt32))
            {
                comparer = new UInt32EqualityComparer();
            }
            else if (t == typeof(UInt64))
            {
                comparer = new UInt64EqualityComparer();
            }
            else if (t == typeof(Single))
            {
                comparer = new SingleEqualityComparer();
            }
            else if (t == typeof(Double))
            {
                comparer = new DoubleEqualityComparer();
            }
            else if (t == typeof(bool))
            {
                comparer = new BoolEqualityComparer();
            }
            else if (t == typeof(byte))
            {
                comparer = new ByteEqualityComparer();
            }
            else if (t == typeof(sbyte))
            {
                comparer = new SByteEqualityComparer();
            }

            else if (t == typeof(String))
            {
                comparer = new StringEqualityComparer();
            }
            else if (t == typeof(Char))
            {
                comparer = new CharEqualityComparer();
            }
            else if (t == typeof(TimeSpan))
            {
                comparer = new TimeSpanEqualityComparer();
            }
            else if (t == typeof(DateTime))
            {
                comparer = new DeteTimeEqualityComparer();
            }
            else if (t == typeof(DateTimeOffset))
            {
                comparer = new DeteTimeOffsetEqualityComparer();
            }
            else if (t == typeof(decimal))
            {
                comparer = new DecimalEqualityComparer();
            }
            else if (t == typeof(Guid))
            {
                comparer = new GuidEqualityComparer();
            }

            else if (t == typeof(Int16?))
            {
                comparer = new NullableEqualityComparer <Int16>();
            }
            else if (t == typeof(Int32?))
            {
                comparer = new NullableEqualityComparer <Int32>();
            }
            else if (t == typeof(Int64?))
            {
                comparer = new NullableEqualityComparer <Int64>();
            }
            else if (t == typeof(UInt16?))
            {
                comparer = new NullableEqualityComparer <UInt16>();
            }
            else if (t == typeof(UInt32?))
            {
                comparer = new NullableEqualityComparer <UInt32>();
            }
            else if (t == typeof(UInt64?))
            {
                comparer = new NullableEqualityComparer <UInt64>();
            }
            else if (t == typeof(Single?))
            {
                comparer = new NullableEqualityComparer <Single>();
            }
            else if (t == typeof(Double?))
            {
                comparer = new NullableEqualityComparer <Double>();
            }
            else if (t == typeof(bool?))
            {
                comparer = new NullableEqualityComparer <bool>();
            }
            else if (t == typeof(byte?))
            {
                comparer = new NullableEqualityComparer <byte>();
            }
            else if (t == typeof(sbyte?))
            {
                comparer = new NullableEqualityComparer <sbyte>();
            }
            else if (t == typeof(Char?))
            {
                comparer = new NullableEqualityComparer <Char>();
            }
            else if (t == typeof(TimeSpan?))
            {
                comparer = new NullableEqualityComparer <TimeSpan>();
            }
            else if (t == typeof(DateTime?))
            {
                comparer = new NullableEqualityComparer <DateTime>();
            }
            else if (t == typeof(DateTimeOffset?))
            {
                comparer = new NullableEqualityComparer <DateTimeOffset>();
            }
            else if (t == typeof(decimal?))
            {
                comparer = new NullableEqualityComparer <decimal>();
            }
            else if (t == typeof(Guid?))
            {
                comparer = new NullableEqualityComparer <Guid>();
            }

#if !UNITY
            else if (t.GetTypeInfo().GetInterfaces().Any(x => x == typeof(IKeyTuple)))
            {
                var ti = t.GetTypeInfo();

                Type keyTupleComparerType = null;
                switch (ti.GetGenericArguments().Length)
                {
                case 1:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <>);
                    break;

                case 2:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <,>);
                    break;

                case 3:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, ,>);
                    break;

                case 4:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , ,>);
                    break;

                case 5:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , , ,>);
                    break;

                case 6:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , , , ,>);
                    break;

                case 7:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , , , , ,>);
                    break;

                case 8:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , , , , , ,>);
                    break;

                default:
                    break;
                }

                var formatterType = keyTupleComparerType.MakeGenericType(ti.GetGenericArguments());
                comparer = Activator.CreateInstance(formatterType);
            }

            // Unity Can't use EnumEqualityComparer.

            else if (t.GetTypeInfo().IsEnum)
            {
                comparer = EnumEqualityComparer <T> .Default;
            }

            else if (t.GetTypeInfo().IsNullable() && t.GetTypeInfo().GenericTypeArguments[0].GetTypeInfo().IsEnum)
            {
                var formatterType = typeof(NullableEqualityComparer <>).MakeGenericType(t.GetTypeInfo().GenericTypeArguments[0]);
                comparer = Activator.CreateInstance(formatterType);
            }
#endif
            return(comparer);
        }
Esempio n. 2
0
        static ZeroFormatterEqualityComparer()
        {
            object comparer = null;

            var t = typeof(T);

            if (t == typeof(Int16))
            {
                comparer = new Int16EqualityComparer();
            }
            else if (t == typeof(Int32))
            {
                comparer = new Int32EqualityComparer();
            }
            else if (t == typeof(Int64))
            {
                comparer = new Int64EqualityComparer();
            }
            else if (t == typeof(UInt16))
            {
                comparer = new UInt16EqualityComparer();
            }
            else if (t == typeof(UInt32))
            {
                comparer = new UInt32EqualityComparer();
            }
            else if (t == typeof(UInt64))
            {
                comparer = new UInt64EqualityComparer();
            }
            else if (t == typeof(Single))
            {
                comparer = new SingleEqualityComparer();
            }
            else if (t == typeof(Double))
            {
                comparer = new DoubleEqualityComparer();
            }
            else if (t == typeof(bool))
            {
                comparer = new BoolEqualityComparer();
            }
            else if (t == typeof(byte))
            {
                comparer = new ByteEqualityComparer();
            }
            else if (t == typeof(sbyte))
            {
                comparer = new SByteEqualityComparer();
            }

            else if (t == typeof(String))
            {
                comparer = new StringEqualityComparer();
            }
            else if (t == typeof(Char))
            {
                comparer = new CharEqualityComparer();
            }
            else if (t == typeof(TimeSpan))
            {
                comparer = new TimeSpanEqualityComparer();
            }
            else if (t == typeof(DateTime))
            {
                comparer = new DeteTimeEqualityComparer();
            }
            else if (t == typeof(DateTimeOffset))
            {
                comparer = new DeteTimeOffsetEqualityComparer();
            }
            else if (t == typeof(decimal))
            {
                comparer = new DecimalEqualityComparer();
            }
            else if (t == typeof(Guid))
            {
                comparer = new GuidEqualityComparer();
            }

#if !UNITY
            else if (t.GetTypeInfo().GetInterfaces().Any(x => x == typeof(IKeyTuple)))
            {
                var ti = t.GetTypeInfo();

                Type keyTupleComparerType = null;
                switch (ti.GetGenericArguments().Length)
                {
                case 1:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <>);
                    break;

                case 2:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <,>);
                    break;

                case 3:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, ,>);
                    break;

                case 4:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , ,>);
                    break;

                case 5:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , , ,>);
                    break;

                case 6:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , , , ,>);
                    break;

                case 7:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , , , , ,>);
                    break;

                case 8:
                    keyTupleComparerType = typeof(KeyTupleEqualityComparer <, , , , , , ,>);
                    break;

                default:
                    break;
                }

                var formatterType = keyTupleComparerType.MakeGenericType(ti.GetGenericArguments());
                comparer = Activator.CreateInstance(formatterType);
            }

            // Unity Can't use EnumEqualityComparer.

            else if (t.GetTypeInfo().IsEnum)
            {
                comparer = EnumEqualityComparer <T> .Default;
            }
#endif

            else
            {
                comparer = new ErrorEqualityComparer <T>();
            }

            defaultComparer = (IEqualityComparer <T>)comparer;
        }