コード例 #1
0
        public TypeMappingSpec <TTgt, TSrc> From <TSrcProp>(Expression <Func <TSrc, TSrcProp> > propertyExpression)
        {
            var srcParam      = Expression.Parameter(typeof(TSrc));
            var tgtParam      = Expression.Parameter(typeof(TTgt));
            var srcExpr       = Expression.Property(srcParam, ((MemberExpression)propertyExpression.Body).Member as PropertyInfo);
            var tgtSetterInfo = _targetProperty.GetSetMethod();
            var tgtSetterExpr = Expression.Call(tgtParam, tgtSetterInfo, srcExpr);

            var setterAction = Expression.Lambda <Action <TTgt, TSrc> >(tgtSetterExpr, tgtParam, srcParam)
                               .Compile();

            var specProperties = _spec.Properties();

            return(_spec
                   .Transforms().WithMappingActions(
                       specProperties.MappingActions
                       .Concat(new[] { setterAction })
                       .ToArray()
                       )
                   .Transforms().WithSourceProperties(
                       specProperties.SourceProperties
                       .Where(x => x != srcExpr.Member)
                       .ToArray()
                       )
                   .Transforms().WithTargetProperties(
                       specProperties.TargetProperties
                       .Where(x => x != _targetProperty)
                       .ToArray()
                       )
                   );
        }
コード例 #2
0
 public TypeMappingSpec <TTgt, TSrc> ReturnNull()
 {
     return(_spec.Transforms()
            .WithAssembler(new ReturnNullAssembler <TTgt, TSrc>()));
 }