<commit_before>using System;
using System.Collections;
using System.Collections.Concurrent;

namespace XSerializer
{
    internal static class JsonSerializerFactory
    {
        private static readonly ConcurrentDictionary<Tuple<Type, bool>, IJsonSerializerInternal> _cache = new ConcurrentDictionary<Tuple<Type, bool>, IJsonSerializerInternal>();

        public static IJsonSerializerInternal GetSerializer(Type type, bool encrypt)
        {
            return _cache.GetOrAdd(
                Tuple.Create(type, encrypt),
                _ =>
                {
                    if (type == typeof(object))
                    {
                        return DynamicJsonSerializer.Get(encrypt);
                    }

                    if (type == typeof(string)
                        || type == typeof(DateTime)
                        || type == typeof(DateTime?)
                        || type == typeof(DateTimeOffset)
                        || type == typeof(DateTimeOffset?)
                        || type == typeof(Guid)
                        || type == typeof(Guid?))
                    {
                        return StringJsonSerializer.Get(type, encrypt);
                    }

                    if (type == typeof(double)
                        || type == typeof(double?)
                        || type == typeof(int)
                        || type == typeof(int?)
                        || type == typeof(float)
                        || type == typeof(float?)
                        || type == typeof(long)
                        || type == typeof(long?)
                        || type == typeof(decimal)
                        || type == typeof(decimal?)
                        || type == typeof(byte)
                        || type == typeof(byte?)
                        || type == typeof(sbyte)
                        || type == typeof(sbyte?)
                        || type == typeof(short)
                        || type == typeof(short?)
                        || type == typeof(ushort)
                        || type == typeof(ushort?)
                        || type == typeof(uint)
                        || type == typeof(uint?)
                        || type == typeof(ulong)
                        || type == typeof(ulong?)) // TODO: handle more number types.
                    {
                        return NumberJsonSerializer.Get(type, encrypt);
                    }

                    if (type == typeof(bool)
                        || type == typeof(bool?))
                    {
                        return BooleanJsonSerializer.Get(encrypt, type == typeof(bool?));
                    }

                    if (type.IsAssignableToGenericIDictionary())
                    {
                        return DictionaryJsonSerializer.Get(type, encrypt);
                    }

                    if (typeof(IEnumerable).IsAssignableFrom(type))
                    {
                        return ListJsonSerializer.Get(type, encrypt);
                    }

                    // TODO: Handle more types or possibly black-list some types or types of types.

                    return CustomJsonSerializer.Get(type, encrypt);
                });
        }
    }
}<commit_msg>Include nongeneric IDictionary<commit_after>using System;
using System.Collections;
using System.Collections.Concurrent;

namespace XSerializer
{
    internal static class JsonSerializerFactory
    {
        private static readonly ConcurrentDictionary<Tuple<Type, bool>, IJsonSerializerInternal> _cache = new ConcurrentDictionary<Tuple<Type, bool>, IJsonSerializerInternal>();

        public static IJsonSerializerInternal GetSerializer(Type type, bool encrypt)
        {
            return _cache.GetOrAdd(
                Tuple.Create(type, encrypt),
                _ =>
                {
                    if (type == typeof(object))
                    {
                        return DynamicJsonSerializer.Get(encrypt);
                    }

                    if (type == typeof(string)
                        || type == typeof(DateTime)
                        || type == typeof(DateTime?)
                        || type == typeof(DateTimeOffset)
                        || type == typeof(DateTimeOffset?)
                        || type == typeof(Guid)
                        || type == typeof(Guid?))
                    {
                        return StringJsonSerializer.Get(type, encrypt);
                    }

                    if (type == typeof(double)
                        || type == typeof(double?)
                        || type == typeof(int)
                        || type == typeof(int?)
                        || type == typeof(float)
                        || type == typeof(float?)
                        || type == typeof(long)
                        || type == typeof(long?)
                        || type == typeof(decimal)
                        || type == typeof(decimal?)
                        || type == typeof(byte)
                        || type == typeof(byte?)
                        || type == typeof(sbyte)
                        || type == typeof(sbyte?)
                        || type == typeof(short)
                        || type == typeof(short?)
                        || type == typeof(ushort)
                        || type == typeof(ushort?)
                        || type == typeof(uint)
                        || type == typeof(uint?)
                        || type == typeof(ulong)
                        || type == typeof(ulong?)) // TODO: handle more number types.
                    {
                        return NumberJsonSerializer.Get(type, encrypt);
                    }

                    if (type == typeof(bool)
                        || type == typeof(bool?))
                    {
                        return BooleanJsonSerializer.Get(encrypt, type == typeof(bool?));
                    }

                    if (type.IsAssignableToGenericIDictionary()
                        || typeof(IDictionary).IsAssignableFrom(type))
                    {
                        return DictionaryJsonSerializer.Get(type, encrypt);
                    }

                    if (typeof(IEnumerable).IsAssignableFrom(type))
                    {
                        return ListJsonSerializer.Get(type, encrypt);
                    }

                    // TODO: Handle more types or possibly black-list some types or types of types.

                    return CustomJsonSerializer.Get(type, encrypt);
                });
        }
    }
}
{'fraction_non_alphanumeric': 0.09965220021170422, 'fraction_numerical': 0.0, 'mean_word_length': 1.05276225946617, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '5813813', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1292, 'n_words': 293}