<commit_before>using AutoMapper.Configuration;
using AutoMapper.Mappers;
using AutoMapper.QueryableExtensions.Impl;

namespace AutoMapper
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Reflection;
    using Configuration;
    using Execution;

    [DebuggerDisplay("{DestinationProperty.Name}")]
    public class PropertyMap
    {
        private readonly TypeMap _typeMap;
        private readonly LinkedList<IValueResolver> _sourceValueResolvers = new LinkedList<IValueResolver>();
        private bool _ignored;
        private int _mappingOrder;
        private IValueResolver _customResolver;
        private IValueResolver _customMemberResolver;
        private bool _sealed;
        private Func<object, object, ResolutionContext, bool> _condition = (_, __, ___) => true;
        private bool _hasCondition;
        private Func<ResolutionContext, bool> _preCondition = _ => true;
        private bool _hasPreCondition;
        private Func<ResolutionContext, object> _valueResolverFunc;
        private Action<object, ResolutionContext> _mapperFunc;
        private MemberInfo _sourceMember;

        public PropertyMap(IMemberAccessor destinationProperty, TypeMap typeMap)
        {
            _typeMap = typeMap;
            UseDestinationValue = true;
            DestinationProperty = destinationProperty;
        }

        public PropertyMap(PropertyMap inheritedMappedProperty, TypeMap typeMap)
            : this(inheritedMappedProperty.DestinationProperty, typeMap)
        {
            if (inheritedMappedProperty.IsIgnored())
                Ignore();
            else
            {
                foreach (var sourceValueResolver in inheritedMappedProperty.GetSourceValueResolvers())
                {
                    ChainResolver(sourceValueResolver);
                }
            }
            ApplyCondition(inheritedMappedProperty._condition);
            SetNullSubstitute(inheritedMappedProperty.NullSubstitute);
            SetMappingOrder(inheritedMappedProperty._mappingOrder);
            CustomExpression = inheritedMappedProperty.CustomExpression;
        }

        public IMemberAccessor DestinationProperty { get; }

        public Type DestinationPropertyType => DestinationProperty.MemberType;

        public LambdaExpression CustomExpression { get; private set; }

        public Type SourceType { get; private set; }

        public MemberInfo SourceMember
        {
            get
            {
                return _sourceMember ?? GetSourceValueResolvers().OfType<IMemberGetter>().LastOrDefault()?.MemberInfo;
            }
            internal set { _sourceMember = value; }
        }

        public bool UseDestinationValue { get; set; }

        internal bool HasCustomValueResolver { get; private set; }

        public bool ExplicitExpansion { get; set; }

        public object NullSubstitute { get; private set; }

        public IEnumerable<IValueResolver> GetSourceValueResolvers()
        {
            if (_customMemberResolver != null)
                yield return _customMemberResolver;

            if (_customResolver != null)
                yield return _customResolver;

            foreach (var resolver in _sourceValueResolvers)
            {
                yield return resolver;
            }

            if (NullSubstitute != null)
                yield return new NullReplacementMethod(NullSubstitute);
        }

        public void RemoveLastResolver()
        {
            _sourceValueResolvers.RemoveLast();
        }

        internal void Seal(TypeMapRegistry typeMapRegistry)
        {
            if (_sealed)
            {
                return;
            }

            var resolvers = GetSourceValueResolvers().ToArray();

            SourceType = resolvers.OfType<IMemberResolver>().LastOrDefault()?.MemberType;

            if (!CanResolveValue())
            {
                _mapperFunc = (_, __) => { };
                return;
            }

            Func<object, ResolutionContext, object> valueResolverFunc = BuildValueResolverFunc(resolvers);

            if (SourceType != null
                && (!SourceType.IsEnumerableType() || SourceType == typeof(string))
                && typeMapRegistry.GetTypeMap(new TypePair(SourceType, DestinationPropertyType)) == null
                && ((EnumMapper.EnumToEnumMapping(new TypePair(SourceType, DestinationPropertyType)) && !EnumMapper.EnumToNullableTypeMapping(new TypePair(SourceType, DestinationPropertyType))) || !EnumMapper.EnumToEnumMapping(new TypePair(SourceType, DestinationPropertyType)))
                && DestinationPropertyType.IsAssignableFrom(SourceType))
            {
                if (_hasCondition)
                {
                    _mapperFunc = (mappedObject, context) => 
                        DestinationProperty.SetValue(mappedObject, ShouldAssignValue(valueResolverFunc(mappedObject, context), GetDestinationValue(mappedObject), context) 
                        ? valueResolverFunc(mappedObject, context) 
                        : GetDestinationValue(mappedObject));
                }
                else
                {
                    _mapperFunc = (mappedObject, context) => DestinationProperty.SetValue(mappedObject, valueResolverFunc(mappedObject, context));
                }
            }
            else
            {
                if (_hasCondition)
                {
                    _mapperFunc = (mappedObject, context) =>
                    {
                        var result = valueResolverFunc(mappedObject, context);

                        object destinationValue = GetDestinationValue(mappedObject);

                        if (!ShouldAssignValue(result, destinationValue, context))
                            return;

                        var sourceType = result?.GetType() ?? SourceType ?? context.SourceType;

                        object propertyValueToAssign = context.Mapper.Map(result, destinationValue, sourceType, DestinationPropertyType, context);

                        DestinationProperty.SetValue(mappedObject, propertyValueToAssign);
                    };

                }<commit_msg>Conditions moved to single expression<commit_after>using AutoMapper.Configuration;
using AutoMapper.Mappers;
using AutoMapper.QueryableExtensions.Impl;

namespace AutoMapper
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Reflection;
    using Configuration;
    using Execution;

    [DebuggerDisplay("{DestinationProperty.Name}")]
    public class PropertyMap
    {
        private readonly TypeMap _typeMap;
        private readonly LinkedList<IValueResolver> _sourceValueResolvers = new LinkedList<IValueResolver>();
        private bool _ignored;
        private int _mappingOrder;
        private IValueResolver _customResolver;
        private IValueResolver _customMemberResolver;
        private bool _sealed;
        private Func<object, object, ResolutionContext, bool> _condition = (_, __, ___) => true;
        private bool _hasCondition;
        private Func<ResolutionContext, bool> _preCondition = _ => true;
        private bool _hasPreCondition;
        private Func<ResolutionContext, object> _valueResolverFunc;
        private Action<object, ResolutionContext> _mapperFunc;
        private MemberInfo _sourceMember;

        public PropertyMap(IMemberAccessor destinationProperty, TypeMap typeMap)
        {
            _typeMap = typeMap;
            UseDestinationValue = true;
            DestinationProperty = destinationProperty;
        }

        public PropertyMap(PropertyMap inheritedMappedProperty, TypeMap typeMap)
            : this(inheritedMappedProperty.DestinationProperty, typeMap)
        {
            if (inheritedMappedProperty.IsIgnored())
                Ignore();
            else
            {
                foreach (var sourceValueResolver in inheritedMappedProperty.GetSourceValueResolvers())
                {
                    ChainResolver(sourceValueResolver);
                }
            }
            ApplyCondition(inheritedMappedProperty._condition);
            SetNullSubstitute(inheritedMappedProperty.NullSubstitute);
            SetMappingOrder(inheritedMappedProperty._mappingOrder);
            CustomExpression = inheritedMappedProperty.CustomExpression;
        }

        public IMemberAccessor DestinationProperty { get; }

        public Type DestinationPropertyType => DestinationProperty.MemberType;

        public LambdaExpression CustomExpression { get; private set; }

        public Type SourceType { get; private set; }

        public MemberInfo SourceMember
        {
            get
            {
                return _sourceMember ?? GetSourceValueResolvers().OfType<IMemberGetter>().LastOrDefault()?.MemberInfo;
            }
            internal set { _sourceMember = value; }
        }

        public bool UseDestinationValue { get; set; }

        internal bool HasCustomValueResolver { get; private set; }

        public bool ExplicitExpansion { get; set; }

        public object NullSubstitute { get; private set; }

        public IEnumerable<IValueResolver> GetSourceValueResolvers()
        {
            if (_customMemberResolver != null)
                yield return _customMemberResolver;

            if (_customResolver != null)
                yield return _customResolver;

            foreach (var resolver in _sourceValueResolvers)
            {
                yield return resolver;
            }

            if (NullSubstitute != null)
                yield return new NullReplacementMethod(NullSubstitute);
        }

        public void RemoveLastResolver()
        {
            _sourceValueResolvers.RemoveLast();
        }

        internal void Seal(TypeMapRegistry typeMapRegistry)
        {
            if (_sealed)
            {
                return;
            }

            var resolvers = GetSourceValueResolvers().ToArray();

            SourceType = resolvers.OfType<IMemberResolver>().LastOrDefault()?.MemberType;

            if (!CanResolveValue())
            {
                _mapperFunc = (_, __) => { };
                return;
            }

            Func<object, ResolutionContext, object> valueResolverFunc = BuildValueResolverFunc(resolvers);

            if (SourceType != null
                && (!SourceType.IsEnumerableType() || SourceType == typeof(string))
                && typeMapRegistry.GetTypeMap(new TypePair(SourceType, DestinationPropertyType)) == null
                && ((EnumMapper.EnumToEnumMapping(new TypePair(SourceType, DestinationPropertyType)) && !EnumMapper.EnumToNullableTypeMapping(new TypePair(SourceType, DestinationPropertyType))) || !EnumMapper.EnumToEnumMapping(new TypePair(SourceType, DestinationPropertyType)))
                && DestinationPropertyType.IsAssignableFrom(SourceType))
            {
                if (_hasCondition)
                {
                    var inner = valueResolverFunc;

                    valueResolverFunc =
                        (mappedObject, context) => 
                        ShouldAssignValue(inner(mappedObject, context), GetDestinationValue(mappedObject), context) 
                        ? inner(mappedObject, context) 
                        : GetDestinationValue(mappedObject);
                }

                _mapperFunc = (mappedObject, context) => DestinationProperty.SetValue(mappedObject, valueResolverFunc(mappedObject, context));
            }
            else
            {
                if (_hasCondition)
                {
                    _mapperFunc = (mappedObject, context) =>
                    {
                        var result = valueResolverFunc(mappedObject, context);

                        object destinationValue = GetDestinationValue(mappedObject);

                        if (!ShouldAssignValue(result, destinationValue, context))
                            return;

                        var sourceType = result?.GetType() ?? SourceType ?? context.SourceType;

                        object propertyValueToAssign = context.Mapper.Map(result, destinationValue, sourceType, DestinationPropertyType, context);

                        DestinationProperty.SetValue(mappedObject, propertyValueToAssign);
                    };

                }
{'fraction_non_alphanumeric': 0.07142857142857142, 'fraction_numerical': 0.0, 'mean_word_length': 2.0670432220039294, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, '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': '7633613', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2800, 'n_words': 595}