Skip to content

Commit 45cb3ba

Browse files
mettolenlbargaoanu
andauthored
Upgrade auto mapper to 12.0.0 (#68)
* Upgrade AutoMapper to 12.0.0 * proper version range * Upgrade AutoMapper to 12.0.0 * Fix build Build.ps1 Co-authored-by: Lucian Bargaoanu <lbargaoanu@users.noreply.github.com>
1 parent 62456e1 commit 45cb3ba

File tree

7 files changed

+34
-36
lines changed

7 files changed

+34
-36
lines changed

AutoMapper.Data.Tests/DataReaderMappingTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Data;
66
using System.Linq;
77
using AutoMapper.Internal;
8-
using Configuration.Conventions;
98
using Mappers;
109
using Shouldly;
1110
using Xunit;

AutoMapper.Data.Tests/ProfileTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System.Collections.Generic;
44
using System.Data;
55
using System.Linq;
6-
using System.Reflection;
7-
using AutoMapper.Data.Configuration.Conventions;
86
using Shouldly;
97
using Xunit;
108

AutoMapper.Data/AutoMapper.Data.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</PropertyGroup>
2626

2727
<ItemGroup>
28-
<PackageReference Include="AutoMapper" Version="[11.0.1, 12.0.0)" />
28+
<PackageReference Include="AutoMapper" Version="[12.0.0, 13.0.0)" />
2929
<None Include="..\README.md" Pack="true" PackagePath="" />
3030
</ItemGroup>
3131

AutoMapper.Data/Configuration/Conventions/DataRecordMemberConfiguration.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Data;
43
using System.Reflection;
54
using System.Reflection.Emit;
65

76
using AutoMapper.Configuration.Conventions;
87
using AutoMapper.Data.Utils;
9-
using AutoMapper.Internal;
8+
using AutoMapper.Internal;
109
using AutoMapper.Utils;
1110

1211
using static System.Reflection.Emit.OpCodes;
@@ -15,11 +14,11 @@
1514

1615
namespace AutoMapper.Data.Configuration.Conventions
1716
{
18-
public class DataRecordMemberConfiguration : IChildMemberConfiguration
19-
{
20-
public bool MapDestinationPropertyToSource(ProfileMap options, TypeDetails sourceType, Type destType, Type destMemberType, string nameToSearch, List<MemberInfo> resolvers, IMemberConfiguration parent, bool isReverseMap)
21-
{
22-
if (TypeExtensions.IsAssignableFrom(typeof(IDataRecord), sourceType.Type))
17+
public class DataRecordMemberConfiguration : ISourceToDestinationNameMapper
18+
{
19+
public MemberInfo GetSourceMember(TypeDetails sourceTypeDetails, Type destType, Type destMemberType, string nameToSearch)
20+
{
21+
if (TypeExtensions.IsAssignableFrom(typeof(IDataRecord), sourceTypeDetails.Type))
2322
{
2423
var returnType = destMemberType;
2524
// TODO: The return type really should be the type of the field in the reader.
@@ -31,13 +30,15 @@ public bool MapDestinationPropertyToSource(ProfileMap options, TypeDetails sourc
3130
EmitPropertyMapping(il, destType, destMemberType, nameToSearch);
3231
il.Emit(Ret);
3332

34-
resolvers.Add(method);
35-
36-
return true;
33+
return method;
3734
}
38-
return false;
39-
}
40-
35+
return null;
36+
}
37+
38+
public void Merge(ISourceToDestinationNameMapper otherNamedMapper)
39+
{
40+
}
41+
4142
private void EmitPropertyMapping(ILGenerator il, Type destType, Type destMemberType, string nameToSearch)
4243
{
4344
var returnType = destMemberType;

AutoMapper.Data/ConfigurationExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using AutoMapper.Data.Configuration.Conventions;
22
using AutoMapper.Data.Mappers;
3-
using AutoMapper.Internal;
4-
3+
using AutoMapper.Internal;
4+
55
namespace AutoMapper.Data
66
{
77
public static class ConfigurationExtensions
@@ -23,6 +23,6 @@ public static void AddDataReaderMapping(this IMapperConfigurationExpression conf
2323
}
2424

2525
public static void AddDataRecordMember(this IProfileExpression profile) =>
26-
profile.Internal().AddMemberConfiguration().AddMember<DataRecordMemberConfiguration>();
26+
profile.Internal().MemberConfiguration.NameToMemberMappers.Add(new DataRecordMemberConfiguration());
2727
}
2828
}

AutoMapper.Data/Utils/CollectionMapper.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using System.Linq.Expressions;
44
using AutoMapper.Execution;
55
using static System.Linq.Expressions.Expression;
66
using static AutoMapper.Utils.ExpressionExtensions;
77

88
namespace AutoMapper.Utils
9-
{
10-
using AutoMapper.Internal;
11-
using AutoMapper.Internal.Mappers;
12-
using System.Collections.Generic;
13-
9+
{
10+
using AutoMapper.Internal;
11+
using AutoMapper.Internal.Mappers;
12+
using System.Collections.Generic;
13+
1414
public static class CollectionMapperExtensions
1515
{
1616
internal static Expression MapCollectionExpression(this IGlobalConfiguration configurationProvider,
@@ -40,7 +40,7 @@ internal static Expression MapCollectionExpression(this IGlobalConfiguration con
4040
Assign(passedDestination, destExpression),
4141
IfThenElse(condition ?? Constant(false),
4242
Block(Assign(newExpression, passedDestination), Call(newExpression, clearMethod)),
43-
Assign(newExpression, passedDestination.Type.NewExpr(ifInterfaceType))),
43+
Assign(newExpression, passedDestination.Type.NewExpr(ifInterfaceType, configurationProvider))),
4444
Condition(Equal(sourceExpression, Constant(null)), ToType(ifNullExpr, passedDestination.Type), ToType(mapExpr, passedDestination.Type))
4545
);
4646
if(memberMap != null)
@@ -60,16 +60,16 @@ internal static Expression MapCollectionExpression(this IGlobalConfiguration con
6060
return Block(checkContext, checkNull);
6161
}
6262

63-
internal static Delegate Constructor(Type type)
63+
internal static Delegate Constructor(Type type, IGlobalConfiguration configuration)
6464
{
65-
return Lambda(ToType(ObjectFactory.GenerateConstructorExpression(type), type)).Compile();
65+
return Lambda(ToType(ObjectFactory.GenerateConstructorExpression(type, configuration), type)).Compile();
6666
}
6767

68-
internal static Expression NewExpr(this Type baseType, Type ifInterfaceType)
68+
internal static Expression NewExpr(this Type baseType, Type ifInterfaceType, IGlobalConfiguration configuration)
6969
{
7070
var newExpr = baseType.IsInterface()
7171
? New(ifInterfaceType.MakeGenericType(TypeHelper.GetElementTypes(baseType, ElementTypeFlags.BreakKeyValuePair)))
72-
: ObjectFactory.GenerateConstructorExpression(baseType);
72+
: ObjectFactory.GenerateConstructorExpression(baseType, configuration);
7373
return ToType(newExpr, baseType);
7474
}
7575

@@ -117,8 +117,8 @@ internal static BinaryExpression IfNotNull(Expression destExpression)
117117
public class CollectionMapper : IObjectMapper
118118
{
119119
public bool IsMatch(TypePair context) => context.SourceType.IsEnumerableType() && context.DestinationType.IsCollectionType();
120-
121-
public Expression MapExpression(IGlobalConfiguration configurationProvider, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression)
122-
=> configurationProvider.MapCollectionExpression(profileMap, memberMap, sourceExpression, destExpression, CollectionMapperExtensions.IfNotNull, typeof(List<>), CollectionMapperExtensions.MapItemExpr);
120+
121+
public Expression MapExpression(IGlobalConfiguration configurationProvider, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression)
122+
=> configurationProvider.MapCollectionExpression(profileMap, memberMap, sourceExpression, destExpression, CollectionMapperExtensions.IfNotNull, typeof(List<>), CollectionMapperExtensions.MapItemExpr);
123123
}
124124
}

Build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ exec { & dotnet clean -c Release }
2929
exec { & dotnet restore }
3030

3131
exec { & dotnet build AutoMapper.Data.sln -c Release -v q /nologo }
32-
exec { & dotnet test -c Release -r $artifacts --no-build -l trx --verbosity=normal }
32+
exec { & dotnet test -c Release --no-build -l trx --verbosity=normal }
3333

34-
exec { & dotnet pack .\AutoMapper.Data -c Release -o artifacts --include-symbols --no-build }
34+
exec { & dotnet pack .\AutoMapper.Data -c Release -o $artifacts --include-symbols --no-build }

0 commit comments

Comments
 (0)