Skip to content

Commit

Permalink
writer mapper building implemented directly in MapperFactory.
Browse files Browse the repository at this point in the history
BuildMapper removed from IMappingAssociation interface
  • Loading branch information
maksimkim committed Aug 30, 2013
1 parent 6f591b5 commit d820a82
Show file tree
Hide file tree
Showing 26 changed files with 328 additions and 802 deletions.
60 changes: 0 additions & 60 deletions src/EntityFunctors/Associations/ComponentCollectionAssociation.cs

This file was deleted.

166 changes: 0 additions & 166 deletions src/EntityFunctors/Associations/ComponentToComponentAssociation.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/EntityFunctors/Associations/ConverterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public Func<object, object> UntypedLambda
var inputType = Expression.Parameters[0].Type;

var param = Exp.Parameter(typeof(object), "_");
//var typed = Exp.Variable(inputType);
var typed = Expression.Parameters[0];
var body = Expression.Apply(typed);

Expand Down
11 changes: 0 additions & 11 deletions src/EntityFunctors/Associations/IMappingAssociation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
[ContractClass(typeof (ContactForMappingAssociation))]
public interface IMappingAssociation
{
Expression BuildMapper(ParameterExpression @from, ParameterExpression to, ParameterExpression propertyKeys, IMappingRegistry registry);

string Key { get; }

MappingDirection Direction { get; }
Expand All @@ -20,15 +18,6 @@ public interface IMappingAssociation
[ContractClassFor(typeof(IMappingAssociation))]
public abstract class ContactForMappingAssociation : IMappingAssociation
{
public Expression BuildMapper(ParameterExpression @from, ParameterExpression to, ParameterExpression propertyKeys, IMappingRegistry registry)
{
Contract.Assert(@from != null);
Contract.Assert(@to != null);
Contract.Assert(registry != null);

return null;
}

public string Key
{
get { return null; }
Expand Down
9 changes: 0 additions & 9 deletions src/EntityFunctors/Associations/IMappingRegistry.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace EntityFunctors.Associations
namespace EntityFunctors.Associations.Impl
{
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq.Expressions;
using Extensions;

public class CollectionAssociation<TSource, TSourceItem, TTarget, TTargetItem>
: CollectionAssociationBase<TSource, TSourceItem, TTarget, TTargetItem>, IConvertionAssociation
Expand All @@ -28,10 +27,5 @@ public CollectionAssociation(Expression<Func<TSource, IEnumerable<TSourceItem>>>

TargetConverter = new ConverterInfo(converter);
}

protected override LambdaExpression CreateSelector(Type @from, Type to, ParameterExpression expands, IMappingRegistry registry)
{
return TargetConverter.Expression;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace EntityFunctors.Associations
namespace EntityFunctors.Associations.Impl
{
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Extensions;
using Fluent;
using EntityFunctors.Extensions;
using EntityFunctors.Associations.Fluent;

public abstract class CollectionAssociationBase<TSource, TSourceItem, TTarget, TTargetItem>
: IMappingAssociation, ICollectionAssociation, IExpandable
Expand Down Expand Up @@ -68,45 +68,6 @@ Expression<Func<TTarget, IEnumerable<TTargetItem>>> target
Key = Target.GetProperty().GetName();
}

public virtual Expression BuildMapper(ParameterExpression @from, ParameterExpression to, ParameterExpression propertyKeys, IMappingRegistry registry)
{
if (!(@from.Type == typeof(TSource) && to.Type == typeof(TTarget)))
return Expression.Empty();

var donor = Source.Apply(@from);
var acceptor = Target.Apply(to);

Expression mapper = Expression.Assign(
acceptor,
Expression.Condition(
donor.CreateCheckForDefault(),
Target.ReturnType.GetDefaultExpression(),
Expression.Convert(
Expression.Call(
ToArray.MakeGenericMethod(TargetItemType),
Expression.Call(
Select.MakeGenericMethod(SourceItemType, TargetItemType),
donor,
CreateSelector(SourceItemType, TargetItemType, propertyKeys, registry)
)
),
Target.ReturnType
)
)
);

if (propertyKeys != null && Expand)
mapper =
Expression.IfThen(
propertyKeys.CreateContains(Expression.Constant(Key, typeof(string))),
mapper
);

return mapper;
}

protected abstract LambdaExpression CreateSelector(Type @from, Type to, ParameterExpression expands, IMappingRegistry registry);

public void Expandable()
{
Expand = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace EntityFunctors.Associations.Impl
{
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

public class ComponentCollectionAssociation<TSource, TSourceItem, TTarget, TTargetItem>
: CollectionAssociationBase<TSource, TSourceItem, TTarget, TTargetItem>, IComponentAssociation
where TSource : class
where TSourceItem : class
where TTarget : class, new()
where TTargetItem: class, new()
{
public TypeMapKey ComponentKey { get; private set; }

public ComponentCollectionAssociation(
Expression<Func<TSource, IEnumerable<TSourceItem>>> source,
Expression<Func<TTarget, IEnumerable<TTargetItem>>> target)
: base(source, target)
{
ComponentKey = new TypeMapKey(SourceItemType, TargetItemType);
}
}
}
Loading

0 comments on commit d820a82

Please sign in to comment.