Skip to content

Commit

Permalink
Merge pull request #37 from AutoMapper/upgrade-8.0
Browse files Browse the repository at this point in the history
Upgrade 8.0
  • Loading branch information
jbogard authored Nov 19, 2018
2 parents 0559662 + faeadea commit 039bc0e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
Binary file added AutoMapper.Data.snk
Binary file not shown.
17 changes: 5 additions & 12 deletions AutoMapper.Data/AutoMapper.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@

<PropertyGroup>
<Description>ADO.NET extensions for AutoMapper</Description>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionPrefix>3.0.0</VersionPrefix>
<Authors>Jimmy Bogard</Authors>
<TargetFrameworks>netstandard1.3;netstandard2.0;net45</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<AssemblyName>AutoMapper.Data</AssemblyName>
<PackageId>AutoMapper.Data</PackageId>
<PackageTags>AutoMapper</PackageTags>
<PackageIconUrl>https://s3.amazonaws.com/automapper/icon.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/AutoMapper/AutoMapper.Data</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/AutoMapper/AutoMapper.Data/blob/master/LICENSE.txt</PackageLicenseUrl>
<Version>2.0.0</Version>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\AutoMapper.Data.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="7.0.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.ILGeneration" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="AutoMapper" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
Expand Down
2 changes: 1 addition & 1 deletion AutoMapper.Data/Mappers/DataReaderMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public bool IsMatch(TypePair context)
=> IsDataReader(context.SourceType, context.DestinationType);

public Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap,
PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
IMemberMap memberMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
{
Expression mapExpr = null;

Expand Down
24 changes: 12 additions & 12 deletions AutoMapper.Data/Utils/CollectionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace AutoMapper.Utils
public static class CollectionMapperExtensions
{
internal static Expression MapCollectionExpression(this IConfigurationProvider configurationProvider,
ProfileMap profileMap, PropertyMap propertyMap, Expression sourceExpression,
ProfileMap profileMap, IMemberMap memberMap, Expression sourceExpression,
Expression destExpression, Expression contextExpression, Func<Expression, Expression> conditionalExpression, Type ifInterfaceType, MapItem mapItem)
{
var passedDestination = Variable(destExpression.Type, "passedDestination");
Expand All @@ -21,12 +21,12 @@ internal static Expression MapCollectionExpression(this IConfigurationProvider c
var sourceElementType = TypeHelper.GetElementType(sourceExpression.Type);
ParameterExpression itemParam;

var itemExpr = mapItem(configurationProvider, profileMap, propertyMap, sourceExpression.Type, passedDestination.Type, contextExpression, out itemParam);
var itemExpr = mapItem(configurationProvider, profileMap, memberMap, sourceExpression.Type, passedDestination.Type, contextExpression, out itemParam);

var destinationElementType = itemExpr.Type;
var destinationCollectionType = typeof(ICollection<>).MakeGenericType(destinationElementType);
var addMethod = destinationCollectionType.GetDeclaredMethod("Add");
var destination = propertyMap?.UseDestinationValue == true ? passedDestination : newExpression;
var destination = memberMap?.UseDestinationValue == true ? passedDestination : newExpression;
var addItems = ForEach(sourceExpression, itemParam, Call(destination, addMethod, itemExpr));

var mapExpr = Block(addItems, destination);
Expand All @@ -41,7 +41,7 @@ internal static Expression MapCollectionExpression(this IConfigurationProvider c
Assign(newExpression, passedDestination.Type.NewExpr(ifInterfaceType))),
Condition(Equal(sourceExpression, Constant(null)), ToType(ifNullExpr, passedDestination.Type), ToType(mapExpr, passedDestination.Type))
);
if(propertyMap != null)
if(memberMap != null)
{
return checkNull;
}
Expand Down Expand Up @@ -72,23 +72,23 @@ internal static Expression NewExpr(this Type baseType, Type ifInterfaceType)
}

public delegate Expression MapItem(IConfigurationProvider configurationProvider, ProfileMap profileMap,
PropertyMap propertyMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam);
IMemberMap memberMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam);

internal static Expression MapItemExpr(this IConfigurationProvider configurationProvider, ProfileMap profileMap,
PropertyMap propertyMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam)
IMemberMap memberMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam)
{
var sourceElementType = TypeHelper.GetElementType(sourceType);
var destElementType = TypeHelper.GetElementType(destType);
itemParam = Parameter(sourceElementType, "item");

var typePair = new TypePair(sourceElementType, destElementType);

var itemExpr = ExpressionBuilder.MapExpression(configurationProvider, profileMap, typePair, itemParam, contextParam, propertyMap);
var itemExpr = ExpressionBuilder.MapExpression(configurationProvider, profileMap, typePair, itemParam, contextParam, memberMap);
return ToType(itemExpr, destElementType);
}

internal static Expression MapKeyPairValueExpr(this IConfigurationProvider configurationProvider,
ProfileMap profileMap, PropertyMap propertyMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam)
ProfileMap profileMap, IMemberMap memberMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam)
{
var sourceElementTypes = TypeHelper.GetElementTypes(sourceType, ElementTypeFlags.BreakKeyValuePair);
var destElementTypes = TypeHelper.GetElementTypes(destType, ElementTypeFlags.BreakKeyValuePair);
Expand All @@ -100,8 +100,8 @@ internal static Expression MapKeyPairValueExpr(this IConfigurationProvider confi
itemParam = Parameter(sourceElementType, "item");
var destElementType = typeof(KeyValuePair<,>).MakeGenericType(destElementTypes);

var keyExpr = ExpressionBuilder.MapExpression(configurationProvider, profileMap, typePairKey, Property(itemParam, "Key"), contextParam, propertyMap);
var valueExpr = ExpressionBuilder.MapExpression(configurationProvider, profileMap, typePairValue, Property(itemParam, "Value"), contextParam, propertyMap);
var keyExpr = ExpressionBuilder.MapExpression(configurationProvider, profileMap, typePairKey, Property(itemParam, "Key"), contextParam, memberMap);
var valueExpr = ExpressionBuilder.MapExpression(configurationProvider, profileMap, typePairValue, Property(itemParam, "Value"), contextParam, memberMap);
var keyPair = New(destElementType.GetConstructors().First(), keyExpr, valueExpr);
return keyPair;
}
Expand All @@ -116,7 +116,7 @@ public class CollectionMapper : IObjectMapper
{
public bool IsMatch(TypePair context) => context.SourceType.IsEnumerableType() && context.DestinationType.IsCollectionType();

public Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
=> configurationProvider.MapCollectionExpression(profileMap, propertyMap, sourceExpression, destExpression, contextExpression, CollectionMapperExtensions.IfNotNull, typeof(List<>), CollectionMapperExtensions.MapItemExpr);
public Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap, IMemberMap memberMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
=> configurationProvider.MapCollectionExpression(profileMap, memberMap, sourceExpression, destExpression, contextExpression, CollectionMapperExtensions.IfNotNull, typeof(List<>), CollectionMapperExtensions.MapItemExpr);
}
}

0 comments on commit 039bc0e

Please sign in to comment.