<commit_before>﻿using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;

namespace Jessica.Helpers
{
    public static class Mapper<T>
        where T : new()
    {
        private static Dictionary<string, PropertyInfo> PropertyMap;

        static Mapper()
        {
            PropertyMap = typeof(T)
                .GetProperties()
                .ToDictionary(p => p.Name.ToLower(), p => p);
        }

        public static void Map(ExpandoObject source, T destination)
        {
            foreach (var kv in source)
            {
                PropertyInfo prop;

                if (!PropertyMap.TryGetValue(kv.Key.ToLower(), out prop))
                {
                    continue;
                }

                if (kv.Value.GetType() != prop.PropertyType)
                {
                    continue;
                }

                prop.SetValue(destination, kv.Value, null);
            }
        }

        public static T Map(ExpandoObject source)
        {
            var model = new T();<commit_msg>Updated Mapper helper to create an instance with Activator, rather than new<commit_after>﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;

namespace Jessica.Helpers
{
    public static class Mapper<T>
        where T : class
    {
        private static Dictionary<string, PropertyInfo> _propertyMap;

        static Mapper()
        {
            _propertyMap = typeof(T)
                .GetProperties()
                .ToDictionary(p => p.Name.ToLower(), p => p);
        }

        public static void Map(ExpandoObject source, T destination)
        {
            foreach (var kv in source)
            {
                PropertyInfo prop;

                if (!_propertyMap.TryGetValue(kv.Key.ToLower(), out prop))
                {
                    continue;
                }

                if (kv.Value.GetType() != prop.PropertyType)
                {
                    continue;
                }

                prop.SetValue(destination, kv.Value, null);
            }
        }

        public static T Map(ExpandoObject source)
        {
            var model = Activator.CreateInstance<T>();
{'fraction_non_alphanumeric': 0.0880141530296329, 'fraction_numerical': 0.0, 'mean_word_length': 1.4375, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, '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': '4528005', 'n_tokens_mistral': 582, 'n_tokens_neox': 549, 'n_words': 143}