void ApplyConverter(MappingStep mapping) { foreach (var pattern in conversionPatterns) { pattern.Apply(mapping); } }
DelegatingConversionStep ApplyConverter(MappingStep mapping, bool withFallback) { dynamic instance = null; try { instance = conversionPatternRepository.LeaseConversionPatternFor(mapping.SourceValueType, mapping.TargetValueType); if (ReferenceEquals((object)instance, null) == false) { var expression = instance.BuildConversionExpression(mapping) as LambdaExpression; if (expression != null) { return new DelegatingConversionStep(expression); } } } finally { conversionPatternRepository.Recycle((object)instance); } if (withFallback == false || mapping.TargetValueType.IsAssignableFrom(mapping.SourceValueType)) { return null; } // fallabck behavior instance = Activator.CreateInstance(typeof (MapConversionPattern<>).MakeGenericType(mapping.TargetValueType)); return new DelegatingConversionStep(instance.BuildConversionExpression(mapping) as LambdaExpression); }
public void Apply(MappingStep mapping) { if (mapping.TargetValueType.IsAssignableFrom(mapping.SourceValueType)) { return; } mapping.Conversion = new MapConversionStep(); }
public void Apply(MappingStep mapping) { if (IsSupportedCollectionType(mapping.SourceProperty.PropertyType) && IsSupportedCollectionType(mapping.TargetProperty.PropertyType)) { mapping.Conversion = new CollectionConversionStep(); } }
public override Expression BuildConversionExpression(MappingStrategy context, MappingStep step) { var from = step.SourceValueType.GetArrayItemType(); var to = step.TargetValueType.GetArrayItemType(); Debug.Assert(from != null); Debug.Assert(to != null); return Expression.Call(MapCollection.MakeGenericMethod(from, to), context.ValueExpression, context.ContextExpression); }
public override Expression BuildConversionExpression(MappingStrategy context, MappingStep step) { var callExpression = (MethodCallExpression)blueprint.Body; if (step.TargetValueType == typeof (object)) { return callExpression; } var method = callExpression.Method.GetGenericMethodDefinition().MakeGenericMethod(step.TargetValueType); return Expression.Call(context.MapperExpression, method, context.ValueExpression); }
public void AddMappingStep(MappingStep mappingStep) { mappingSteps.Add(mappingStep); }
static Expression BuildParameterExpression(MappingStep step, MappingStrategy strategy) { var map = step.Apply(strategy, step.Conversion); return map; }
public abstract Expression BuildConversionExpression(MappingStrategy context, MappingStep step);
public DelegatingConversionStep ApplyConverter(MappingStep mapping, bool withFallback) { return applyConverter(mapping, withFallback); }