Skip to content

Commit 42e01cb

Browse files
committed
Replacing MapperSpecifier use with MapUsing(), DeepCloneUsing() and FlattenUsing() extension methods
1 parent 6572dd4 commit 42e01cb

File tree

5 files changed

+26
-64
lines changed

5 files changed

+26
-64
lines changed

AgileMapper.UnitTests/Extensions/WhenFlatteningToQueryStringViaExtensionMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void ShouldFlattenWithASpecifiedMapper()
2727
mapper.After.MappingEnds.Call(ctx => callbackCalled = true);
2828

2929
var source = new Address { Line1 = "Here", Line2 = "There" };
30-
var result = source.Flatten(_ => _.Using(mapper)).ToQueryString();
30+
var result = source.FlattenUsing(mapper).ToQueryString();
3131

3232
callbackCalled.ShouldBeTrue();
3333
result.ShouldBe("Line1=Here&Line2=There");

AgileMapper.UnitTests/Extensions/WhenFlatteningViaExtensionMethods.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void ShouldFlattenToDynamicWithASpecifiedMapper()
4343
new Address { Line1 = "3_1", Line2 = "3_2" }
4444
};
4545

46-
var result = source.Flatten(_ => _.Using(mapper)).ToDynamic();
46+
var result = source.FlattenUsing(mapper).ToDynamic();
4747

4848
((string)result._0Line1).ShouldBe("1_1");
4949
((string)result._0Line2).ShouldBe("1_2");
@@ -93,7 +93,7 @@ public void ShouldFlattenToDynamicWithInlineConfigurationAndASpecifiedMapper()
9393
new Address { Line1 = "3_1", Line2 = "3_2" }
9494
};
9595

96-
var result = source.Flatten(_ => _.Using(mapper)).ToDynamic(cfg => cfg
96+
var result = source.FlattenUsing(mapper).ToDynamic(cfg => cfg
9797
.ForDynamics
9898
.UseElementKeyPattern("_i_"));
9999

@@ -144,7 +144,7 @@ public void ShouldFlattenToDictionaryWithASpecifiedMapper()
144144
new Address { Line1 = "3_1", Line2 = "3_2" }
145145
};
146146

147-
var result = source.Flatten(_ => _.Using(mapper)).ToDictionary();
147+
var result = source.FlattenUsing(mapper).ToDictionary();
148148

149149
result["-0-Line1"].ShouldBe("1_1");
150150
result["-0-Line2"].ShouldBe("1_2");
@@ -199,7 +199,7 @@ public void ShouldFlattenToDictionaryWithInlineConfigurationAndASpecifiedMapper(
199199
new Address { Line1 = "2_1", Line2 = "2_2" }
200200
};
201201

202-
var result = source.Flatten(_ => _.Using(mapper)).ToDictionary(cfg => cfg
202+
var result = source.FlattenUsing(mapper).ToDictionary(cfg => cfg
203203
.ForDictionaries
204204
.UseElementKeyPattern("(i)"));
205205

@@ -248,7 +248,7 @@ public void ShouldFlattenToStringDictionaryWithASpecifiedMapper()
248248
new Address { Line1 = "3_1", Line2 = "3_2" }
249249
};
250250

251-
var result = source.Flatten(_ => _.Using(mapper)).ToDictionary<string>();
251+
var result = source.FlattenUsing(mapper).ToDictionary<string>();
252252

253253
result["-0-Line1"].ShouldBe("1_1");
254254
result["-0-Line2"].ShouldBe("1_2");

AgileMapper.UnitTests/Extensions/WhenMappingViaExtensionMethods.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void ShouldCreateNewWithASpecifiedMapper()
2929
.ToCtor<string>();
3030

3131
var source = new PublicField<int> { Value = 20 };
32-
var result = source.Map(_ => _.Using(mapper)).ToANew<PublicCtorStruct<string>>();
32+
var result = source.MapUsing(mapper).ToANew<PublicCtorStruct<string>>();
3333

3434
result.Value.ShouldBe("40");
3535
}
@@ -72,7 +72,7 @@ public void ShouldDeepCloneWithASpecifiedMapper()
7272
.To(p => p.Value1);
7373

7474
var source = new PublicTwoFieldsStruct<int, int> { Value1 = 123, Value2 = 456 };
75-
var result = source.DeepClone(_ => _.Using(mapper));
75+
var result = source.DeepCloneUsing(mapper);
7676

7777
result.ShouldNotBe(source);
7878
result.Value1.ShouldBe(456);
@@ -131,7 +131,7 @@ public void ShouldMergeWithASpecifiedMapper()
131131
var source = new PublicField<int> { Value = 20 };
132132
var target = new PublicField<string>();
133133

134-
source.Map(_ => _.Using(mapper)).OnTo(target);
134+
source.MapUsing(mapper).OnTo(target);
135135

136136
target.Value.ShouldBe("10");
137137
}
@@ -186,7 +186,7 @@ public void ShouldOverwriteWithASpecifiedMapper()
186186
var source = new PublicField<int> { Value = 20 };
187187
var target = new PublicProperty<string>();
188188

189-
source.Map(_ => _.Using(mapper)).Over(target);
189+
source.MapUsing(mapper).Over(target);
190190

191191
target.Value.ShouldBe("30");
192192
}
@@ -223,7 +223,7 @@ public void ShouldOverwriteWithInlineConfigurationAndASpecifiedMapper()
223223
var source = new PublicTwoFields<int, int> { Value1 = 20, Value2 = 20 };
224224
var target = new PublicTwoFields<string, string>();
225225

226-
source.Map(_ => _.Using(mapper)).Over(target, cfg => cfg
226+
source.MapUsing(mapper).Over(target, cfg => cfg
227227
.Map((s, t) => s.Value2 + 5)
228228
.To(ptf => ptf.Value2));
229229

AgileMapper/Extensions/MapperSpecifier.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

AgileMapper/Extensions/MappingExtensions.cs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,17 @@ public static class MappingExtensions
2020
public static ITargetSelector<TSource> Map<TSource>(this TSource source) => Mapper.Map(source);
2121

2222
/// <summary>
23-
/// Perform a mapping operation on this <paramref name="source"/> object using the <see cref="IMapper"/>
24-
/// specified by the <paramref name="mapperSpecifier"/>.
23+
/// Perform a mapping operation on this <paramref name="source"/> object using the given
24+
/// <paramref name="mapper"/>.
2525
/// </summary>
2626
/// <typeparam name="TSource">The type of source object on which to perform the mapping.</typeparam>
2727
/// <param name="source">The source object on which to perform the mapping.</param>
28-
/// <param name="mapperSpecifier">
29-
/// A func supplying the <see cref="IMapper"/> instance with which to perform the object creation.
28+
/// <param name="mapper">
29+
/// The <see cref="IMapper"/> instance with which to perform the object creation.
3030
/// </param>
3131
/// <returns>A TargetSelector with which to specify the type of mapping to perform.</returns>
32-
public static ITargetSelector<TSource> Map<TSource>(
33-
this TSource source,
34-
Func<MapperSpecifier, IMapper> mapperSpecifier)
35-
{
36-
return MapperSpecifier.Get(mapperSpecifier).Map(source);
37-
}
32+
public static ITargetSelector<TSource> MapUsing<TSource>(this TSource source, IMapper mapper)
33+
=> mapper.Map(source);
3834

3935
/// <summary>
4036
/// Perform a deep clone of this <paramref name="instance"/> using the default <see cref="IMapper"/>.
@@ -45,17 +41,14 @@ public static ITargetSelector<TSource> Map<TSource>(
4541
public static T DeepClone<T>(this T instance) => Mapper.Default.DeepClone(instance);
4642

4743
/// <summary>
48-
/// Perform a deep clone of this <paramref name="instance"/> using the <see cref="IMapper"/>
49-
/// specified by the <paramref name="mapperSpecifier"/>.
44+
/// Perform a deep clone of this <paramref name="instance"/> using the given <paramref name="mapper"/>.
5045
/// </summary>
5146
/// <typeparam name="T">The Type of object to clone.</typeparam>
5247
/// <param name="instance">The object to clone.</param>
53-
/// <param name="mapperSpecifier">
54-
/// A func supplying the <see cref="IMapper"/> instance with which to perform the deep clone.
55-
/// </param>
48+
/// <param name="mapper">The <see cref="IMapper"/> instance with which to perform the deep clone.</param>
5649
/// <returns>A deep clone of this <paramref name="instance"/>.</returns>
57-
public static T DeepClone<T>(this T instance, Func<MapperSpecifier, IMapper> mapperSpecifier)
58-
=> MapperSpecifier.Get(mapperSpecifier).DeepClone(instance);
50+
public static T DeepCloneUsing<T>(this T instance, IMapper mapper)
51+
=> mapper.DeepClone(instance);
5952

6053
/// <summary>
6154
/// Perform a deep clone of this <paramref name="instance"/> using the default <see cref="IMapper"/> and
@@ -87,19 +80,15 @@ public static IFlatteningSelector<TSource> Flatten<TSource>(this TSource source)
8780

8881
/// <summary>
8982
/// Flatten the given <paramref name="source"/> object so it has only value-type or string members,
90-
/// using the Mapper specified by the <paramref name="mapperSpecifier"/>.
83+
/// using the given <paramref name="mapper"/>.
9184
/// </summary>
9285
/// <typeparam name="TSource">The type of object to flatten.</typeparam>
9386
/// <param name="source">The object to flatten.</param>
94-
/// <param name="mapperSpecifier">
95-
/// A func supplying the <see cref="IMapper"/> instance with which to perform the flattening.
87+
/// <param name="mapper">
88+
/// The <see cref="IMapper"/> instance with which to perform the flattening.
9689
/// </param>
9790
/// <returns>A FlatteningTypeSelector with which to select the type of flattening to perform.</returns>
98-
public static IFlatteningSelector<TSource> Flatten<TSource>(
99-
this TSource source,
100-
Func<MapperSpecifier, IMapper> mapperSpecifier)
101-
{
102-
return MapperSpecifier.Get(mapperSpecifier).Flatten(source);
103-
}
91+
public static IFlatteningSelector<TSource> FlattenUsing<TSource>(this TSource source, IMapper mapper)
92+
=> mapper.Flatten(source);
10493
}
10594
}

0 commit comments

Comments
 (0)