<commit_before>﻿using System.Linq;
using System.Reflection;

namespace Moll
{
    public class AutomaticMapper<TSrc, TDest> : IMapper<TSrc, TDest>
        where TSrc : class
        where TDest : class, new()
    {
        private readonly PropertyInfo[] _srcPropertyInfos;
        private readonly PropertyInfo[] _destPropertyInfos;

        public AutomaticMapper()
        {
            _srcPropertyInfos = typeof (TSrc)
                .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);

            _destPropertyInfos = typeof (TDest)
                .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);
        }

        public TDest Map(TSrc src)
        {
            if (src == null) return null;

            var dest = new TDest();

            foreach (var srcProp in _srcPropertyInfos)
            {
                var destProp = _destPropertyInfos
                    .FirstOrDefault(x => x.Name == srcProp.Name && x.PropertyType == srcProp.PropertyType);

                if (destProp == null) continue;

                destProp.SetValue(dest, srcProp.GetValue(src));
            }

            AdditionalCustomMapping(src, dest);

            return dest;
        }

        public virtual void AdditionalCustomMapping(TSrc src, TDest dest)
        {
            
        }
    }
}<commit_msg>pre-build src -> dest property mappings<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Moll
{
    public class AutomaticMapper<TSrc, TDest> : IMapper<TSrc, TDest>
        where TSrc : class
        where TDest : class, new()
    {
        private readonly IReadOnlyCollection<Tuple<PropertyInfo, PropertyInfo>> _propertyInfoMappings; 

        public AutomaticMapper()
        {
            var srcPropertyInfos = typeof (TSrc)
                .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);

            var destPropertyInfos = typeof (TDest)
                .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);

            _propertyInfoMappings = (from srcProp in srcPropertyInfos
                                     let destProp =
                                         destPropertyInfos.FirstOrDefault(
                                             x => x.Name == srcProp.Name && x.PropertyType == srcProp.PropertyType)
                                     where destProp != null
                                     select new Tuple<PropertyInfo, PropertyInfo>(srcProp, destProp)).ToList();
        }

        public TDest Map(TSrc src)
        {
            if (src == null) return null;

            var dest = new TDest();

            foreach (var mapping in _propertyInfoMappings)
            {
                mapping.Item2.SetValue(dest, mapping.Item1.GetValue(src));
            }

            AdditionalCustomMapping(src, dest);

            return dest;
        }

        public virtual void AdditionalCustomMapping(TSrc src, TDest dest)
        {
            
        }
    }
}
{'fraction_non_alphanumeric': 0.07933461292386436, 'fraction_numerical': 0.0006397952655150352, 'mean_word_length': 1.7697077059344553, 'pattern_counts': {'":': 0, '<': 10, '<?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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4092960', 'n_tokens_mistral': 799, 'n_tokens_neox': 755, 'n_words': 184}