<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using HellBrick.Json.Utils;
using static System.Linq.Expressions.Expression;

namespace HellBrick.Json.Deserialization.Providers
{
	internal class StringParsingDeserializerBuilderProvider : IDeserializerBuilderProvider
	{
		private static readonly Dictionary<Type, object> _builderLookup =
			(
				from nestedType in typeof( StringParsingDeserializerBuilderProvider ).GetTypeInfo().DeclaredNestedTypes
				where !nestedType.IsAbstract
				from @interface in nestedType.ImplementedInterfaces
				let interfaceInfo = @interface.GetTypeInfo()
				where interfaceInfo.IsGenericType
				where interfaceInfo.GetGenericTypeDefinition() == typeof( IDeserializerBuilder<> )
				let builderTypeArgument = interfaceInfo.GenericTypeArguments[ 0 ]
				select new
				{
					Builder = Activator.CreateInstance( nestedType.AsType() ),
					Type = builderTypeArgument
				}
			)
			.ToDictionary( i => i.Type, i => i.Builder );


		public IDeserializerBuilder<T> TryCreateBuilder<T>() => _builderLookup.GetOrDefault( typeof( T ) ) as IDeserializerBuilder<T>;
	}
}<commit_msg>Added bool? builder<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using HellBrick.Json.Utils;
using static System.Linq.Expressions.Expression;

namespace HellBrick.Json.Deserialization.Providers
{
	internal class StringParsingDeserializerBuilderProvider : IDeserializerBuilderProvider
	{
		private static readonly Dictionary<Type, object> _builderLookup =
			(
				from nestedType in typeof( StringParsingDeserializerBuilderProvider ).GetTypeInfo().DeclaredNestedTypes
				where !nestedType.IsAbstract
				from @interface in nestedType.ImplementedInterfaces
				let interfaceInfo = @interface.GetTypeInfo()
				where interfaceInfo.IsGenericType
				where interfaceInfo.GetGenericTypeDefinition() == typeof( IDeserializerBuilder<> )
				let builderTypeArgument = interfaceInfo.GenericTypeArguments[ 0 ]
				select new
				{
					Builder = Activator.CreateInstance( nestedType.AsType() ),
					Type = builderTypeArgument
				}
			)
			.ToDictionary( i => i.Type, i => i.Builder );


		public IDeserializerBuilder<T> TryCreateBuilder<T>() => _builderLookup.GetOrDefault( typeof( T ) ) as IDeserializerBuilder<T>;

		private class BooleanDeserializerBuilder : RelayDeserializerBuilder<bool?, string>
		{
			protected override Expression ConvertToOuter( Expression inner )
			{
				ParameterExpression text = Parameter( typeof( string ) );
				return Block
				(
					new ParameterExpression[] { text },
					Assign( text, inner ),
					Condition
					(
						Equal( text, Constant( null, typeof( string ) ) ),
						Default( typeof( bool? ) ),
						Convert
						(
							Call( null, Reflection.Method( () => Boolean.Parse( default( string ) ) ), text ),
							typeof( bool? )
						)
					)
				);
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.09199483537766301, 'fraction_numerical': 0.0006455777921239509, 'mean_word_length': 4.36159169550173, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 21, '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': '21093', 'n_tokens_mistral': 1021, 'n_tokens_neox': 856, 'n_words': 198}