コード例 #1
0
 void ApplyConverter(MappingStep mapping)
 {
     foreach (var pattern in conversionPatterns)
     {
         pattern.Apply(mapping);
     }
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 public void Apply(MappingStep mapping)
 {
     if (mapping.TargetValueType.IsAssignableFrom(mapping.SourceValueType))
     {
         return;
     }
     mapping.Conversion = new MapConversionStep();
 }
コード例 #4
0
 public void Apply(MappingStep mapping)
 {
     if (IsSupportedCollectionType(mapping.SourceProperty.PropertyType) &&
         IsSupportedCollectionType(mapping.TargetProperty.PropertyType))
     {
         mapping.Conversion = new CollectionConversionStep();
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
 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);
 }
コード例 #7
0
 public void AddMappingStep(MappingStep mappingStep)
 {
     mappingSteps.Add(mappingStep);
 }
コード例 #8
0
 static Expression BuildParameterExpression(MappingStep step, MappingStrategy strategy)
 {
     var map = step.Apply(strategy, step.Conversion);
     return map;
 }
コード例 #9
0
 public abstract Expression BuildConversionExpression(MappingStrategy context, MappingStep step);
コード例 #10
0
 public DelegatingConversionStep ApplyConverter(MappingStep mapping, bool withFallback)
 {
     return applyConverter(mapping, withFallback);
 }