private static void ProcessNestedAccesses( IMemberMapperData mapperData, ref Expression value, out Expression[] nestedAccesses, out ICollection <ParameterExpression> variables) { nestedAccesses = mapperData.GetNestedAccessesIn(value, targetCanBeNull: false); variables = new List <ParameterExpression>(); if (nestedAccesses.None()) { return; } var nestedAccessVariableByNestedAccess = new Dictionary <Expression, Expression>(); for (var i = 0; i < nestedAccesses.Length; i++) { var nestedAccess = nestedAccesses[i]; if (CacheValueInVariable(nestedAccess)) { var valueVariable = Expression.Variable(nestedAccess.Type, "accessValue"); nestedAccesses[i] = Expression.Assign(valueVariable, nestedAccess); nestedAccessVariableByNestedAccess.Add(nestedAccess, valueVariable); variables.Add(valueVariable); } } value = value.Replace(nestedAccessVariableByNestedAccess); }
public Expression GetConditionOrNull( IMemberMapperData mapperData, CallbackPosition position, QualifiedMember targetMember) { if (!HasCondition) { return(GetTypeCheckConditionOrNull(mapperData)); } var condition = _conditionLambda.GetBody(mapperData, position, targetMember); if (_negateCondition) { condition = Expression.Not(condition); } var targetCanBeNull = position.IsPriorToObjectCreation(targetMember); var conditionNestedAccessesChecks = mapperData .GetNestedAccessesIn(condition, targetCanBeNull) .GetIsNotDefaultComparisonsOrNull(); if (conditionNestedAccessesChecks != null) { condition = Expression.AndAlso(conditionNestedAccessesChecks, condition); } var typeCheck = GetTypeCheckConditionOrNull(mapperData); if (typeCheck != null) { condition = Expression.AndAlso(typeCheck, condition); } return(condition); }