<commit_before>#if FAT
﻿using System;
using System.Collections.Generic;
using System.Reflection;

using Theraot.Collections;

namespace Theraot.Core
{
    public static class EqualityComparerHelper<T>
    {
        private static IEqualityComparer<T> _default;

        static EqualityComparerHelper()
        {
            var type = typeof(T);
            PropertyInfo property = null;
            if (type.IsImplementationOf(typeof(IEquatable<>).MakeGenericType(type)))
            {
                property = GetPropertyDelegated(type, typeof(EqualityComparer<>));
            }
            else if (type.IsAssignableTo(typeof(Delegate)))
            {
                property = typeof(DelegateEqualityComparer).GetProperty("Default", BindingFlags.Public | BindingFlags.Static);
            }
            else if (type.IsGenericInstanceOf(typeof(KeyValuePair<,>)))
            {
                property = GetProperty(type, typeof(KeyValuePairEqualityComparer<,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,,,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,,,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,,,,,>));
            }
            else
            {
                property = GetPropertyDelegated(type, typeof(EqualityComparer<>));
            }
            _default = (IEqualityComparer<T>)property.GetValue(null, null);
        }

        public static IEqualityComparer<T> Default
        {
            get
            {
                return _default;
            }
        }

        private static PropertyInfo GetProperty(Type type, Type equalityComparerType)
        {
            Type[] genericTypeArguments = type.GetGenericArguments();
            Type generticType = equalityComparerType.MakeGenericType(genericTypeArguments);
            return generticType.GetProperty("Default", BindingFlags.Public | BindingFlags.Static);
        }

        private static PropertyInfo GetPropertyDelegated(Type type, Type equalityComparerType)
        {
            Type generticType = equalityComparerType.MakeGenericType(type);
            return generticType.GetProperty("Default", BindingFlags.Public | BindingFlags.Static);
        }
    }
}
#endif<commit_msg>NeedleConversionEqualityComparer now supported<commit_after>#if FAT

using System;
using System.Collections.Generic;
using System.Reflection;
using Theraot.Collections;
using Theraot.Collections.Specialized;
using Theraot.Threading.Needles;

namespace Theraot.Core
{
    public static class EqualityComparerHelper<T>
    {
        private static IEqualityComparer<T> _default;

        static EqualityComparerHelper()
        {
            var type = typeof(T);
            Type tmp;
            PropertyInfo property = null;
            if (type.IsImplementationOf(typeof(IEquatable<>).MakeGenericType(type)))
            {
                property = GetPropertyDelegated(type, typeof(EqualityComparer<>));
            }
            else if (type.IsAssignableTo(typeof(Delegate)))
            {
                property = typeof(DelegateEqualityComparer).GetProperty("Default", BindingFlags.Public | BindingFlags.Static);
            }
            else if (type.IsGenericImplementationOf(typeof(INeedle<>), out tmp))
            {
                var types = tmp.GetGenericArguments();
                var conversionType = typeof(NeedleConversionEqualityComparer<,>).MakeGenericType(new Type[] { tmp, types[0] });
                _default = (IEqualityComparer<T>)(conversionType.Create(GetPropertyDelegated(types[0], typeof(EqualityComparerHelper<>)).GetValue(null, null)));
                return;
            }
            else if (type.IsGenericInstanceOf(typeof(KeyValuePair<,>)))
            {
                property = GetProperty(type, typeof(KeyValuePairEqualityComparer<,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,,,,>));
            }
            else if (type.IsGenericInstanceOf(typeof(Tuple<,,,,,,,>)))
            {
                property = GetProperty(type, typeof(TupleEqualityComparer<,,,,,,,>));
            }
            else
            {
                property = GetPropertyDelegated(type, typeof(EqualityComparer<>));
            }
            _default = (IEqualityComparer<T>)property.GetValue(null, null);
        }

        public static IEqualityComparer<T> Default
        {
            get
            {
                return _default;
            }
        }

        private static PropertyInfo GetProperty(Type type, Type equalityComparerType)
        {
            Type[] genericTypeArguments = type.GetGenericArguments();
            Type generticType = equalityComparerType.MakeGenericType(genericTypeArguments);
            return generticType.GetProperty("Default", BindingFlags.Public | BindingFlags.Static);
        }

        private static PropertyInfo GetPropertyDelegated(Type type, Type equalityComparerType)
        {
            Type generticType = equalityComparerType.MakeGenericType(type);
            return generticType.GetProperty("Default", BindingFlags.Public | BindingFlags.Static);
        }
    }
}

#endif
{'fraction_non_alphanumeric': 0.11289893617021277, 'fraction_numerical': 0.00026595744680851064, 'mean_word_length': 2.132444814660558, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '664280', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1919, 'n_words': 306}