Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Linq.Expressions;
using System.Reflection;
using AgileMapper.Configuration;
using DataSources;
using DataSources.Factories;
using Extensions;
using Extensions.Internal;
using Members;
Expand All @@ -24,7 +24,7 @@
#endif

internal class CustomDataSourceTargetMemberSpecifier<TSource, TTarget> :
ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget>,
ICustomDataSourceTargetMemberSpecifier<TSource, TTarget>,
ICustomProjectionDataSourceTargetMemberSpecifier<TSource, TTarget>
{
private readonly MappingConfigInfo _configInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace AgileObjects.AgileMapper.Api.Configuration.Dictionaries
using System.Linq.Expressions;
using AgileMapper.Configuration;
using AgileMapper.Configuration.Dictionaries;
using DataSources;
using DataSources.Factories;
#if FEATURE_DYNAMIC
using Dynamics;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// </summary>
/// <typeparam name="TSource">The source type to which the configuration should apply.</typeparam>
/// <typeparam name="TTarget">The target type to which the configuration should apply.</typeparam>
public interface ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget>
public interface ICustomDataSourceTargetMemberSpecifier<TSource, TTarget>
{
/// <summary>
/// Apply the configuration to the given <paramref name="targetMember"/>.
Expand Down
18 changes: 9 additions & 9 deletions AgileMapper/Api/Configuration/IRootMappingConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ ICustomDataSourceMappingConfigContinuation<TSource, TTarget> Map<TSourceValue, T
/// An ICustomDataSourceMappingConfigContinuation with which to control the reverse configuration, or further
/// configure mappings from and to the source and target type being configured.
/// </returns>
ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
Expression<Func<IMappingData<TSource, TTarget>, TSourceValue>> valueFactoryExpression);

/// <summary>
Expand All @@ -138,10 +138,10 @@ ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue
/// <typeparam name="TSourceValue">The type of the custom value being configured.</typeparam>
/// <param name="valueFactoryExpression">The expression to map to the configured target member.</param>
/// <returns>
/// An ICustomMappingDataSourceTargetMemberSpecifier with which to specify the target member to which the
/// An ICustomDataSourceTargetMemberSpecifier with which to specify the target member to which the
/// custom value should be applied.
/// </returns>
ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
Expression<Func<TSource, TTarget, TSourceValue>> valueFactoryExpression);

/// <summary>
Expand All @@ -152,10 +152,10 @@ ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue
/// <typeparam name="TSourceValue">The type of the custom value being configured.</typeparam>
/// <param name="valueFactoryExpression">The expression to map to the configured target member.</param>
/// <returns>
/// An ICustomMappingDataSourceTargetMemberSpecifier with which to specify the target member to which the
/// An ICustomDataSourceTargetMemberSpecifier with which to specify the target member to which the
/// custom value should be applied.
/// </returns>
ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
Expression<Func<TSource, TTarget, int?, TSourceValue>> valueFactoryExpression);

/// <summary>
Expand All @@ -164,10 +164,10 @@ ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue
/// <typeparam name="TSourceValue">The type of value returned by the given Func.</typeparam>
/// <param name="valueFunc">The Func object to map to the configured target member.</param>
/// <returns>
/// An ICustomMappingDataSourceTargetMemberSpecifier with which to specify the target member to which the
/// An ICustomDataSourceTargetMemberSpecifier with which to specify the target member to which the
/// custom value should be applied.
/// </returns>
ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> MapFunc<TSourceValue>(
ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> MapFunc<TSourceValue>(
Func<TSource, TSourceValue> valueFunc);

/// <summary>
Expand All @@ -177,10 +177,10 @@ ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> MapFunc<TSourceV
/// <typeparam name="TSourceValue">The type of the custom constant value being configured.</typeparam>
/// <param name="value">The constant value to map to the configured target member.</param>
/// <returns>
/// An ICustomMappingDataSourceTargetMemberSpecifier with which to specify the target member to which the
/// An ICustomDataSourceTargetMemberSpecifier with which to specify the target member to which the
/// custom constant value should be applied.
/// </returns>
ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(TSourceValue value);
ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(TSourceValue value);

/// <summary>
/// Configure a constant value for the given <paramref name="targetMember"/> when mapping from and to the
Expand Down
10 changes: 5 additions & 5 deletions AgileMapper/Api/Configuration/MappingConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public ICustomDataSourceMappingConfigContinuation<TSource, TTarget> Map<TSourceV
return GetValueFactoryTargetMemberSpecifier<TSourceValue>(valueFactoryExpression).To(targetMember);
}

public ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
public ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
Expression<Func<IMappingData<TSource, TTarget>, TSourceValue>> valueFactoryExpression)
{
return GetValueFactoryTargetMemberSpecifier<TSourceValue>(valueFactoryExpression);
Expand All @@ -361,23 +361,23 @@ public ICustomProjectionDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TS
return GetValueFactoryTargetMemberSpecifier<TSourceValue>(valueFactoryExpression);
}

public ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
public ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
Expression<Func<TSource, TTarget, TSourceValue>> valueFactoryExpression)
{
return GetValueFactoryTargetMemberSpecifier<TSourceValue>(valueFactoryExpression);
}

public ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
public ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(
Expression<Func<TSource, TTarget, int?, TSourceValue>> valueFactoryExpression)
{
return GetValueFactoryTargetMemberSpecifier<TSourceValue>(valueFactoryExpression);
}

public ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> MapFunc<TSourceValue>(
public ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> MapFunc<TSourceValue>(
Func<TSource, TSourceValue> valueFunc)
=> GetConstantValueTargetMemberSpecifier(valueFunc);

public ICustomMappingDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(TSourceValue value)
public ICustomDataSourceTargetMemberSpecifier<TSource, TTarget> Map<TSourceValue>(TSourceValue value)
=> GetConstantValueTargetMemberSpecifier(value);

public IMappingConfigContinuation<TSource, TTarget> Map<TSourceValue, TTargetValue>(
Expand Down
2 changes: 1 addition & 1 deletion AgileMapper/Configuration/ConfiguredIgnoredMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AgileObjects.AgileMapper.Configuration
#else
using System.Linq.Expressions;
#endif
using DataSources;
using DataSources.Factories;
using Members;
using ReadableExpressions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
using System;
using System.Dynamic;
using DataSources;
using DataSources.Factories;
using Members;
using ReadableExpressions.Extensions;
#if NET35
Expand Down
11 changes: 6 additions & 5 deletions AgileMapper/Configuration/UserConfigurationSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
#if NET35
using Microsoft.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using DataSources;
using DataSources.Factories;
using Dictionaries;
using Extensions;
using Extensions.Internal;
using Members;
using ObjectPopulation;
using Projection;
using ReadableExpressions.Extensions;
#if NET35
using Microsoft.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif

internal class UserConfigurationSet
{
Expand Down
9 changes: 6 additions & 3 deletions AgileMapper/DataSources/AdHocDataSource.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace AgileObjects.AgileMapper.DataSources
{
using System.Collections.Generic;
#if NET35
using Microsoft.Scripting.Ast;
#else
Expand All @@ -27,8 +26,12 @@ public AdHocDataSource(
IQualifiedMember sourceMember,
Expression value,
Expression condition,
ICollection<ParameterExpression> variables = null)
: base(sourceMember, variables ?? Enumerable<ParameterExpression>.EmptyArray, value, condition)
params ParameterExpression[] variables)
: base(
sourceMember,
variables,
value,
condition)
{
}
}
Expand Down
65 changes: 65 additions & 0 deletions AgileMapper/DataSources/ComplexTypeDataSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace AgileObjects.AgileMapper.DataSources
{
#if NET35
using Microsoft.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using Extensions.Internal;
using Members;
using ObjectPopulation;
using ObjectPopulation.ComplexTypes;

internal class ComplexTypeDataSource : DataSourceBase
{
private ComplexTypeDataSource(IDataSource wrappedDataSource, Expression mapping)
: base(wrappedDataSource, mapping)
{
}

private ComplexTypeDataSource(IQualifiedMember sourceMember, Expression mapping)
: base(sourceMember, mapping)
{
}

#region Factory Methods

public static IDataSource Create(IObjectMappingData mappingData)
{
var mapping = ComplexTypeMappingExpressionFactory.Instance.Create(mappingData);

return new ComplexTypeDataSource(mappingData.MapperData.SourceMember, mapping);
}

public static IDataSource Create(
IDataSource wrappedDataSource,
int dataSourceIndex,
IChildMemberMappingData complexTypeMappingData)
{
var mapping = MappingFactory.GetChildMapping(
wrappedDataSource.SourceMember,
wrappedDataSource.Value,
dataSourceIndex,
complexTypeMappingData);

return new ComplexTypeDataSource(wrappedDataSource, mapping);
}

public static IDataSource Create(int dataSourceIndex, IChildMemberMappingData complexTypeMappingData)
{
var complexTypeMapperData = complexTypeMappingData.MapperData;
var relativeMember = complexTypeMapperData.SourceMember.RelativeTo(complexTypeMapperData.SourceMember);
var sourceMemberAccess = relativeMember.GetQualifiedAccess(complexTypeMapperData);

var mapping = MappingFactory.GetChildMapping(
relativeMember,
sourceMemberAccess,
dataSourceIndex,
complexTypeMappingData);

return new ComplexTypeDataSource(complexTypeMapperData.SourceMember, mapping);
}

#endregion
}
}
55 changes: 0 additions & 55 deletions AgileMapper/DataSources/ComplexTypeMappingDataSource.cs

This file was deleted.

25 changes: 14 additions & 11 deletions AgileMapper/DataSources/DataSourceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected DataSourceBase(IDataSource wrappedDataSource, Expression value)

protected DataSourceBase(
IQualifiedMember sourceMember,
ICollection<ParameterExpression> variables,
IList<ParameterExpression> variables,
Expression value,
Expression condition = null)
{
Expand Down Expand Up @@ -180,26 +180,29 @@ private static bool IsNotOptionalEntityMemberId(IMemberMapperData mapperData)
public Expression SourceMemberTypeTest { get; protected set; }

public virtual bool IsValid => Value != Constants.EmptyExpression;

public virtual Expression PreCondition => null;


public bool IsConditional => Condition != null;

public virtual bool IsFallback => false;

public virtual Expression Condition { get; }

public ICollection<ParameterExpression> Variables { get; }
public IList<ParameterExpression> Variables { get; }

public Expression Value { get; }

public virtual Expression AddPreCondition(Expression population) => population;

public Expression AddCondition(Expression value, Expression alternateBranch = null)
public virtual Expression Finalise(Expression memberPopulation, Expression alternatePopulation)
{
return alternateBranch != null
? Expression.IfThenElse(Condition, value, alternateBranch)
: Expression.IfThen(Condition, value);
if (IsConditional)
{
memberPopulation = (alternatePopulation != null)
? Expression.IfThenElse(Condition, memberPopulation, alternatePopulation)
: Expression.IfThen(Condition, memberPopulation);
}

return memberPopulation;
}

public virtual Expression AddSourceCondition(Expression value) => value;
}
}
Loading