<commit_before>namespace AgileObjects.AgileMapper.ObjectPopulation
{
    using System;
    using Extensions;
    using Members;

    internal interface IObjectMappingCommand<out T>
    {
        T Execute();

        IObjectMappingContext ToOmc();
    }

    internal class ObjectMappingCommand
    {
        public static ObjectMappingCommand<TSource, TTarget> Create<TSource, TTarget>(
            IQualifiedMember sourceMember,
            TSource source,
            QualifiedMember targetMember,
            TTarget target,
            int? enumerableIndex,
            MappingContext mappingContext)
        {
            sourceMember = sourceMember.WithType(source.GetRuntimeSourceType());

            var targetMemberData = GetTargetData(sourceMember, targetMember, target, mappingContext);

            return new ObjectMappingCommand<TSource, TTarget>(
                targetMemberData.SourceMember,
                source,
                targetMemberData.TargetMember,
                target,
                enumerableIndex,
                mappingContext);
        }

        private static MemberPair GetTargetData<TTarget>(
            IQualifiedMember sourceMember,
            QualifiedMember targetMember,
            TTarget target,
            MappingContext mappingContext)
        {
            var mappingData = new BasicMappingData(mappingContext.RuleSet, sourceMember.Type, typeof(TTarget));

            var targetMemberType = mappingContext.MapperContext.UserConfigurations.GetDerivedTypeOrNull(mappingData)
                ?? target.GetRuntimeTargetType(sourceMember.Type);

            targetMember = targetMember.WithType(targetMemberType);

            return new MemberPair(sourceMember, targetMember);
        }

        #region Helper Classes

        private class MemberPair
        {
            public MemberPair(IQualifiedMember sourceMember, QualifiedMember targetMember)
            {
                SourceMember = sourceMember;
                TargetMember = targetMember;
            }

            public IQualifiedMember SourceMember { get; }

            public QualifiedMember TargetMember { get; }
        }

        private class BasicMappingData : IMappingData
        {
            public BasicMappingData(
                MappingRuleSet ruleSet,
                Type sourceType,
                Type targetType)
            {
                SourceType = sourceType;
                TargetType = targetType;
                RuleSetName = ruleSet.Name;
            }

            public IMappingData Parent => null;

            public string RuleSetName { get; }

            public Type SourceType { get; }

            public Type TargetType { get; }

            public QualifiedMember TargetMember => QualifiedMember.All;
        }

        #endregion
    }

    internal class ObjectMappingCommand<TSource, TTarget> : IObjectMappingCommand<TTarget>
    {
        public ObjectMappingCommand(
            IQualifiedMember sourceMember,
            TSource source,
            QualifiedMember targetMember,
            TTarget target,
            int? enumerableIndex,
            MappingContext mappingContext)
        {
            Source = source;
            SourceMember = sourceMember;

            Target = target;
            TargetMember = targetMember;

            EnumerableIndex = enumerableIndex;
            MappingContext = mappingContext;
        }

        public TSource Source { get; }

        public IQualifiedMember SourceMember { get; }

        public TTarget Target { get; }

        public QualifiedMember TargetMember { get; }

        public int? EnumerableIndex { get; }

        public MappingContext MappingContext { get; }

        public TTarget Execute() => MappingContext.MapChild(this);<commit_msg>Removing use of MappingPair helper class in command creation<commit_after>namespace AgileObjects.AgileMapper.ObjectPopulation
{
    using System;
    using Extensions;
    using Members;

    internal interface IObjectMappingCommand<out T>
    {
        T Execute();

        IObjectMappingContext ToOmc();
    }

    internal class ObjectMappingCommand
    {
        public static ObjectMappingCommand<TSource, TTarget> Create<TSource, TTarget>(
            IQualifiedMember sourceMember,
            TSource source,
            QualifiedMember targetMember,
            TTarget target,
            int? enumerableIndex,
            MappingContext mappingContext)
        {
            sourceMember = sourceMember.WithType(source.GetRuntimeSourceType());
            targetMember = GetTargetMember(sourceMember, targetMember, target, mappingContext);

            return new ObjectMappingCommand<TSource, TTarget>(
                sourceMember,
                source,
                targetMember,
                target,
                enumerableIndex,
                mappingContext);
        }

        private static QualifiedMember GetTargetMember<TTarget>(
            IQualifiedMember sourceMember,
            QualifiedMember targetMember,
            TTarget target,
            MappingContext mappingContext)
        {
            var mappingData = new BasicMappingData(mappingContext.RuleSet, sourceMember.Type, typeof(TTarget));

            var targetMemberType =
                mappingContext.MapperContext.UserConfigurations.GetDerivedTypeOrNull(mappingData)
                    ?? target.GetRuntimeTargetType(sourceMember.Type);

            targetMember = targetMember.WithType(targetMemberType);
            return targetMember;
        }

        #region Helper Classes

        private class BasicMappingData : IMappingData
        {
            public BasicMappingData(
                MappingRuleSet ruleSet,
                Type sourceType,
                Type targetType)
            {
                SourceType = sourceType;
                TargetType = targetType;
                RuleSetName = ruleSet.Name;
            }

            public IMappingData Parent => null;

            public string RuleSetName { get; }

            public Type SourceType { get; }

            public Type TargetType { get; }

            public QualifiedMember TargetMember => QualifiedMember.All;
        }

        #endregion
    }

    internal class ObjectMappingCommand<TSource, TTarget> : IObjectMappingCommand<TTarget>
    {
        public ObjectMappingCommand(
            IQualifiedMember sourceMember,
            TSource source,
            QualifiedMember targetMember,
            TTarget target,
            int? enumerableIndex,
            MappingContext mappingContext)
        {
            Source = source;
            SourceMember = sourceMember;

            Target = target;
            TargetMember = targetMember;

            EnumerableIndex = enumerableIndex;
            MappingContext = mappingContext;
        }

        public TSource Source { get; set; }

        public IQualifiedMember SourceMember { get; }

        public TTarget Target { get; set; }

        public QualifiedMember TargetMember { get; }

        public int? EnumerableIndex { get; set; }

        public MappingContext MappingContext { get; }

        public TTarget Execute() => MappingContext.MapChild(this);
{'fraction_non_alphanumeric': 0.05634777793160736, 'fraction_numerical': 0.0, 'mean_word_length': 1.8942307692307692, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '2490099', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1587, 'n_words': 395}