public Expression GetShortCircuit(IObjectMappingData mappingData) { var mapperData = mappingData.MapperData; var dictionaryVariables = new DictionaryEntryVariablePair(mapperData); var fallbackValue = GetFallbackValue(mappingData); var noMatchingKeys = dictionaryVariables.GetNoKeysWithMatchingStartQuery(); var returnFallback = Expression.Return(mapperData.ReturnLabelTarget, fallbackValue); var ifNoMatchingKeysShortCircuit = Expression.IfThen(noMatchingKeys, returnFallback); var foundValueNonNull = dictionaryVariables.Value.GetIsNotDefaultComparison(); var entryExistsTest = GetEntryExistsTest(dictionaryVariables); var mapValueCall = GetMapValueCall(dictionaryVariables.Value, mapperData); var valueMappingOrFallback = Expression.Condition(foundValueNonNull, mapValueCall, fallbackValue); var returnMapValueResult = Expression.Return(mapperData.ReturnLabelTarget, valueMappingOrFallback); var ifEntryExistsShortCircuit = Expression.IfThen(entryExistsTest, returnMapValueResult); return(Expression.Block( dictionaryVariables.Variables, ifNoMatchingKeysShortCircuit, ifEntryExistsShortCircuit)); }
public SourceElementsDictionaryPopulationLoopData( DictionaryEntryVariablePair dictionaryVariables, EnumerablePopulationBuilder builder) { _dictionaryVariables = dictionaryVariables; _builder = builder; var sourceDictionaryMember = dictionaryVariables.SourceMember; _performElementChecks = ElementTypesAreSimple || sourceDictionaryMember.HasObjectEntries || (builder.Context.ElementTypesAreAssignable && !sourceDictionaryMember.ValueType.IsSimple()); _targetMemberKey = dictionaryVariables .GetTargetMemberDictionaryEnumerableElementKey(builder.Counter, MapperData); _useDirectValueAccess = ElementTypesAreSimple ? builder.Context.ElementTypesAreAssignable : sourceDictionaryMember.HasObjectEntries; var useSeparateTargetKeyVariable = !ElementTypesAreSimple && _performElementChecks; _targetElementKey = useSeparateTargetKeyVariable ? Expression.Variable(typeof(string), "targetElementKey") : dictionaryVariables.Key; _sourceElement = _useDirectValueAccess ? GetDictionaryEntryValueAccess() : dictionaryVariables.Value; ContinueLoopTarget = Expression.Label(typeof(void), "Continue"); LoopExitCheck = MapperData.IsRoot ? GetRootLoopExitCheck() : GetKeyNotFoundLoopExitCheck(); }
public SourceElementsDictionaryAdapter( DictionarySourceMember sourceMember, EnumerablePopulationBuilder builder) : base(builder) { _dictionaryVariables = new DictionaryEntryVariablePair(sourceMember, builder.MapperData); }
public SourceInstanceDictionaryAdapter( DictionarySourceMember sourceMember, EnumerablePopulationBuilder builder) : base(builder) { _defaultAdapter = new DefaultSourceEnumerableAdapter(builder); DictionaryVariables = new DictionaryEntryVariablePair(sourceMember, builder.MapperData); }
public SourceObjectDictionaryPopulationLoopData( Expression emptyTarget, DictionaryEntryVariablePair dictionaryVariables, EnumerablePopulationBuilder builder) { _emptyTarget = emptyTarget; _builder = builder; _enumerableLoopData = new EnumerableSourcePopulationLoopData(builder); _elementsDictionaryLoopData = new SourceElementsDictionaryPopulationLoopData(dictionaryVariables, builder); _sourceEnumerableFound = Parameters.Create <bool>("sourceEnumerableFound"); ContinueLoopTarget = Expression.Label(typeof(void), "Continue"); LoopExitCheck = GetCompositeLoopExitCheck(); }
private static Expression GetEntryExistsTest(DictionaryEntryVariablePair dictionaryVariables) { var returnLabel = Expression.Label(typeof(bool), "Return"); var returnFalse = Expression.Return(returnLabel, false.ToConstantExpression()); var ifKeyNotFoundReturnFalse = dictionaryVariables.GetKeyNotFoundShortCircuit(returnFalse); var valueAssignment = dictionaryVariables.GetEntryValueAssignment(); var returnTrue = Expression.Label(returnLabel, true.ToConstantExpression()); if (dictionaryVariables.HasConstantTargetMemberKey) { return(Expression.Block(ifKeyNotFoundReturnFalse, valueAssignment, returnTrue)); } var keyAssignment = dictionaryVariables.GetNonConstantKeyAssignment(); return(Expression.Block( keyAssignment, ifKeyNotFoundReturnFalse, valueAssignment, returnTrue)); }