Skip to content

Commit f53f003

Browse files
committed
Removing essentially pointless object -> target type mapping functions from mapping plans
1 parent 386c5c5 commit f53f003

File tree

10 files changed

+70
-343
lines changed

10 files changed

+70
-343
lines changed

AgileMapper.UnitTests/WhenUsingPartialTrust.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,18 @@ public MappingException TestMappingException()
179179

180180
public void TestMappingPlan()
181181
{
182-
var plan = Mapper
182+
string plan = Mapper
183183
.GetPlanFor<PublicTwoFields<object, object[]>>()
184184
.Over<PublicTwoFields<Customer, IEnumerable<Customer>>>();
185185

186186
Assert.Contains(
187187
"// Map PublicTwoFields<object, object[]> -> PublicTwoFields<Customer, IEnumerable<Customer>>",
188188
plan);
189189

190-
Assert.Contains("// Map object -> Customer", plan);
191-
Assert.Contains("// Map object -> Address", plan);
192190
Assert.Contains("// Rule Set: Overwrite", plan);
191+
Assert.Contains("ptfooaToPtfccData.Map(", plan);
192+
Assert.Contains("\"Value1\"", plan);
193+
Assert.Contains("customers.Add(oaToCsData.Map(objectArray[i]", plan);
193194
}
194195
}
195196
}

AgileMapper.UnitTests/WhenViewingMappingPlans.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.Linq;
56
using System.Text.RegularExpressions;
67
using Shouldly;
78
using TestClasses;
@@ -188,9 +189,8 @@ public void ShouldShowMapChildCalls()
188189
.ToANew<PublicSetMethod<Customer>>();
189190

190191
plan.ShouldContain("// Map PublicProperty<object> -> PublicSetMethod<Customer>");
191-
plan.ShouldContain("// Map object -> Customer");
192-
plan.ShouldContain("// Map object -> Address");
193192
plan.ShouldContain("ppoToPsmcData.Map(");
193+
plan.ShouldContain("\"SetValue\"");
194194
}
195195

196196
[Fact]
@@ -202,8 +202,8 @@ public void ShouldShowNestedMapChildCalls()
202202

203203
plan.ShouldContain("// Map PublicProperty<PublicField<object>> -> PublicSetMethod<PublicProperty<Order>>");
204204
plan.ShouldNotContain("// Map PublicField<object> -> PublicProperty<Order>");
205-
plan.ShouldContain("// Map object -> Order");
206205
plan.ShouldContain("pfoToPpoData.Map(");
206+
plan.ShouldContain("\"Value\"");
207207
}
208208

209209
[Fact]
@@ -214,7 +214,6 @@ public void ShouldShowMapElementCalls()
214214
.ToANew<PublicSetMethod<ICollection<Product>>>();
215215

216216
plan.ShouldContain("// Map PublicProperty<object[]> -> PublicSetMethod<ICollection<Product>>");
217-
plan.ShouldContain("// Map object -> Product");
218217
plan.ShouldContain("products.Add(oaToPsData.Map(objectArray[i]");
219218
}
220219

@@ -242,15 +241,13 @@ public void ShouldShowObjectTracking()
242241
}
243242

244243
[Fact]
245-
public void ShouldNotDuplicateChildMappingPlans()
244+
public void ShouldNotIncludeChildObjectToTargetMappingPlans()
246245
{
247246
string plan = Mapper
248247
.GetPlanFor<PublicTwoFields<object, object>>()
249248
.ToANew<PublicTwoParamCtor<Product, Product>>();
250249

251-
var numberOfObjectToProductPlans = Regex.Matches(plan, "// Map object -> Product").Count;
252-
253-
numberOfObjectToProductPlans.ShouldBe(1);
250+
Regex.Matches(plan, "// Map object -> Product").Cast<Match>().ShouldBeEmpty();
254251
}
255252

256253
[Fact]

AgileMapper/Api/IPlanTargetTypeAndRuleSetSelector.cs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ public interface IPlanTargetTypeAndRuleSetSelector<TSource>
2020
/// </summary>
2121
/// <typeparam name="TResult">The type of object for which to create the mapping plan.</typeparam>
2222
/// <returns>
23-
/// A <see cref="MappingPlan{TSource,TTarget}"/> object detailing the function to be executed
24-
/// during a mapping. To see a string representation of the function assign the result to a string
25-
/// variable, or call .ToString().
23+
/// A <see cref="MappingPlan"/> object detailing the function to be executed during a mapping. To see
24+
/// a string representation of the function assign the result to a string variable, or call .ToString().
2625
/// </returns>
27-
MappingPlan<TSource, TResult> ToANew<TResult>();
26+
MappingPlan ToANew<TResult>();
2827

2928
/// <summary>
3029
/// Create and compile mapping functions for a create new mapping from the source type being
@@ -36,11 +35,10 @@ public interface IPlanTargetTypeAndRuleSetSelector<TSource>
3635
/// <paramref name="configurations"/> with any configuration already set up via the Mapper.WhenMapping API.
3736
/// </param>
3837
/// <returns>
39-
/// A <see cref="MappingPlan{TSource,TTarget}"/> object detailing the function to be executed
40-
/// during a mapping. To see a string representation of the function assign the result to a string
41-
/// variable, or call .ToString().
38+
/// A <see cref="MappingPlan"/> object detailing the function to be executed during a mapping. To see
39+
/// a string representation of the function assign the result to a string variable, or call .ToString().
4240
/// </returns>
43-
MappingPlan<TSource, TResult> ToANew<TResult>(
41+
MappingPlan ToANew<TResult>(
4442
params Expression<Action<IFullMappingInlineConfigurator<TSource, TResult>>>[] configurations);
4543

4644
/// <summary>
@@ -49,11 +47,10 @@ MappingPlan<TSource, TResult> ToANew<TResult>(
4947
/// </summary>
5048
/// <typeparam name="TTarget">The type of object for which to create the mapping plan.</typeparam>
5149
/// <returns>
52-
/// A <see cref="MappingPlan{TSource,TTarget}"/> detailing the function to be executed during a mapping.
53-
/// To see a string representation of the function, assign the result to an explitly-typed string variable,
54-
/// or call .ToString().
50+
/// A <see cref="MappingPlan"/> object detailing the function to be executed during a mapping. To see
51+
/// a string representation of the function assign the result to a string variable, or call .ToString().
5552
/// </returns>
56-
MappingPlan<TSource, TTarget> OnTo<TTarget>();
53+
MappingPlan OnTo<TTarget>();
5754

5855
/// <summary>
5956
/// Create and compile mapping functions for an OnTo (merge) mapping from the source type being
@@ -65,11 +62,10 @@ MappingPlan<TSource, TResult> ToANew<TResult>(
6562
/// <paramref name="configurations"/> with any configuration already set up via the Mapper.WhenMapping API.
6663
/// </param>
6764
/// <returns>
68-
/// A <see cref="MappingPlan{TSource,TTarget}"/> detailing the function to be executed during a mapping.
69-
/// To see a string representation of the function, assign the result to an explitly-typed string variable,
70-
/// or call .ToString().
65+
/// A <see cref="MappingPlan"/> object detailing the function to be executed during a mapping. To see
66+
/// a string representation of the function assign the result to a string variable, or call .ToString().
7167
/// </returns>
72-
MappingPlan<TSource, TTarget> OnTo<TTarget>(
68+
MappingPlan OnTo<TTarget>(
7369
params Expression<Action<IFullMappingInlineConfigurator<TSource, TTarget>>>[] configurations);
7470

7571
/// <summary>
@@ -78,11 +74,10 @@ MappingPlan<TSource, TTarget> OnTo<TTarget>(
7874
/// </summary>
7975
/// <typeparam name="TTarget">The type of object for which to create the mapping plan.</typeparam>
8076
/// <returns>
81-
/// A <see cref="MappingPlan{TSource,TTarget}"/> detailing the function to be executed during a mapping.
82-
/// To see a string representation of the function, assign the result to an explitly-typed string variable,
83-
/// or call .ToString().
77+
/// A <see cref="MappingPlan"/> object detailing the function to be executed during a mapping. To see
78+
/// a string representation of the function assign the result to a string variable, or call .ToString().
8479
/// </returns>
85-
MappingPlan<TSource, TTarget> Over<TTarget>();
80+
MappingPlan Over<TTarget>();
8681

8782
/// <summary>
8883
/// Create and compile mapping functions for an Over (overwrite) mapping from the source type being
@@ -94,11 +89,10 @@ MappingPlan<TSource, TTarget> OnTo<TTarget>(
9489
/// <paramref name="configurations"/> with any configuration already set up via the Mapper.WhenMapping API.
9590
/// </param>
9691
/// <returns>
97-
/// A <see cref="MappingPlan{TSource,TTarget}"/> detailing the function to be executed during a mapping.
98-
/// To see a string representation of the function, assign the result to an explitly-typed string variable,
99-
/// or call .ToString().
92+
/// A <see cref="MappingPlan"/> object detailing the function to be executed during a mapping. To see
93+
/// a string representation of the function assign the result to a string variable, or call .ToString().
10094
/// </returns>
101-
MappingPlan<TSource, TTarget> Over<TTarget>(
95+
MappingPlan Over<TTarget>(
10296
params Expression<Action<IFullMappingInlineConfigurator<TSource, TTarget>>>[] configurations);
10397
}
10498
}

AgileMapper/Api/PlanTargetTypeSelector.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ public MappingPlanSet To<TTarget>(
3232
.ToArray());
3333
}
3434

35-
public MappingPlan<TSource, TResult> ToANew<TResult>()
35+
public MappingPlan ToANew<TResult>()
3636
=> GetMappingPlan<TResult>(_mapperContext.RuleSets.CreateNew);
3737

38-
public MappingPlan<TSource, TResult> ToANew<TResult>(
38+
public MappingPlan ToANew<TResult>(
3939
Expression<Action<IFullMappingInlineConfigurator<TSource, TResult>>>[] configurations)
4040
=> GetMappingPlan(_mapperContext.RuleSets.CreateNew, configurations);
4141

42-
public MappingPlan<TSource, TTarget> OnTo<TTarget>()
42+
public MappingPlan OnTo<TTarget>()
4343
=> GetMappingPlan<TTarget>(_mapperContext.RuleSets.Merge);
4444

45-
public MappingPlan<TSource, TTarget> OnTo<TTarget>(
45+
public MappingPlan OnTo<TTarget>(
4646
Expression<Action<IFullMappingInlineConfigurator<TSource, TTarget>>>[] configurations)
4747
=> GetMappingPlan(_mapperContext.RuleSets.Merge, configurations);
4848

49-
public MappingPlan<TSource, TTarget> Over<TTarget>()
49+
public MappingPlan Over<TTarget>()
5050
=> GetMappingPlan<TTarget>(_mapperContext.RuleSets.Overwrite);
5151

52-
public MappingPlan<TSource, TTarget> Over<TTarget>(
52+
public MappingPlan Over<TTarget>(
5353
Expression<Action<IFullMappingInlineConfigurator<TSource, TTarget>>>[] configurations)
5454
=> GetMappingPlan(_mapperContext.RuleSets.Overwrite, configurations);
5555

56-
private MappingPlan<TSource, TTarget> GetMappingPlan<TTarget>(
56+
private MappingPlan GetMappingPlan<TTarget>(
5757
MappingRuleSet ruleSet,
5858
IEnumerable<Expression<Action<IFullMappingInlineConfigurator<TSource, TTarget>>>> configurations = null)
5959
{
@@ -65,7 +65,7 @@ private MappingPlan<TSource, TTarget> GetMappingPlan<TTarget>(
6565
.ConfigureMapperContext(configurations, planContext);
6666
}
6767

68-
return new MappingPlan<TSource, TTarget>(planContext);
68+
return MappingPlan.For<TSource, TTarget>(planContext);
6969
}
7070
}
7171
}

AgileMapper/ObjectPopulation/Enumerables/ReadOnlyCollectionWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public ReadOnlyCollectionWrapper(IList<T> existingItems, int numberOfNewItems)
9999
#endregion
100100
public T this[int index]
101101
{
102-
get { return _items[index]; }
103-
set { _items[index] = value; }
102+
get => _items[index];
103+
set => _items[index] = value;
104104
}
105105

106106
#endregion

AgileMapper/Plans/CachedMapperMappingPlan.cs

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

0 commit comments

Comments
 (0)