private Expression BuildWriterBody(Expression from, Expression to, ParameterExpression explicitProperties) { var mapKey = new TypeMapKey(@from.Type, to.Type); IEnumerable <IMappingAssociation> associations; if (!_registry.TryGetValue(mapKey, out associations)) { throw new InvalidOperationException( string.Format("Unable to create mapper from {0} to {1}. Check appropriate mappings exist and loaded.", @from.Type, to.Type) ); } var body = new List <Expression>(); foreach (var association in associations) { var item = BuildWriterItem(association, @from, to, explicitProperties); if (item != null) { body.Add(item); } } return (body.Count > 0 ? (Expression)Expression.Block(body) : Expression.Empty()); }
public ComponentCollectionAssociation( Expression <Func <TSource, IEnumerable <TSourceItem> > > source, Expression <Func <TTarget, IEnumerable <TTargetItem> > > target) : base(source, target) { ComponentKey = new TypeMapKey(SourceItemType, TargetItemType); }
public ComponentToComponentAssociation(Expression <Func <TSource, TSourceComponent> > source, Expression <Func <TTarget, TTargetComponent> > target) { Contract.Assert(source != null); Contract.Assert(target != null); PropertyInfo prop; Contract.Assert(source.Body.TryGetProperty(out prop)); Contract.Assert(target.Body.TryGetProperty(out prop)); Source = source; Target = target; target.GetProperty(); Key = Target.GetProperty().GetName(); Direction = MappingDirection.All; ComponentKey = new TypeMapKey(Source.ReturnType, Target.ReturnType); }
private Expression BuildReaderBody(Expression @from, Type targetType, ParameterExpression expands) { var mapKey = new TypeMapKey(from.Type, targetType); IEnumerable <IMappingAssociation> associations; if (!_registry.TryGetValue(mapKey, out associations)) { throw new InvalidOperationException( string.Format("Unable to create mapper from {0} to {1}. Check appropriate mappings exist and loaded.", from.Type, targetType) ); } var bindings = new List <MemberBinding>(); var ctor = targetType.GetConstructor(Type.EmptyTypes); if (ctor == null) { throw new InvalidOperationException( string.Format("Type {0} must declare public parameterless constructor to be mapped from {1}", targetType, from.Type) ); } foreach (var association in associations) { var item = BuildReaderItem(association, from, expands); if (item != null) { bindings.Add(Expression.Bind(association.Target.GetProperty(), item)); } } return(Expression.MemberInit(Expression.New(ctor), bindings)); }
public BeanSpec(Type type, string beanName, string constructorName) : base(type, beanName, constructorName) { _typeMapKey = new TypeMapKey(this); }
protected bool Equals(TypeMapKey other) { return(Equals(_beanSpec._type, other._beanSpec._type) && string.Equals(_beanSpec._beanName, other._beanSpec._beanName)); }
public TestMap(Type from, Type to, params IMappingAssociation[] associations) { Associations = associations; Key = new TypeMapKey(from, to); }