Skip to content

Commit f16ba80

Browse files
committed
Various optimisations brought in from OptimiseMapperSetup
1 parent 4ed697f commit f16ba80

40 files changed

+164
-175
lines changed

AgileMapper.UnitTests/Dictionaries/WhenCreatingRootDictionaryMembers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
using System.Collections.Generic;
44
using AgileMapper.Members;
55
using AgileMapper.Members.Dictionaries;
6+
using Members;
67
using TestClasses;
78
using Xunit;
89

9-
public class WhenCreatingRootDictionaryMembers
10+
public class WhenCreatingRootDictionaryMembers : MemberTestsBase
1011
{
1112
[Fact]
1213
public void ShouldVarySourceMembersByTargetType()
1314
{
14-
var memberFactory = new QualifiedMemberFactory(MapperContext.Default);
15+
var memberFactory = new QualifiedMemberFactory(DefaultMapperContext);
1516

1617
var dictionaryToPersonArraySourceMember = memberFactory
1718
.RootSource<Dictionary<string, Person[]>, Person[]>()

AgileMapper.UnitTests/Members/MemberTestsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public abstract class MemberTestsBase
1111
{
12-
internal static readonly MapperContext DefaultMapperContext = MapperContext.Default;
12+
internal static readonly MapperContext DefaultMapperContext = new MapperContext();
1313
internal static readonly MemberCache MemberCache = GlobalContext.Instance.MemberCache;
1414

1515
internal IQualifiedMember SourceMemberFor<T>(T sourceObject)

AgileMapper.UnitTests/Members/WhenCreatingTargetMembersFromExpressions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void ShouldCreateASetMethodMember()
4444
{
4545
Expression<Func<PublicSetMethod<int>, Action<int>>> setMethodAccess = x => x.SetValue;
4646

47-
var fieldMember = setMethodAccess.Body.ToTargetMember(MapperContext.Default);
47+
var fieldMember = setMethodAccess.Body.ToTargetMember(DefaultMapperContext);
4848

4949
fieldMember.Members().Count().ShouldBe(2);
5050

AgileMapper/Api/PlanTargetSelector.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ internal PlanTargetSelector(MapperContext mapperContext)
3535
public MappingPlanSet To<TTarget>(
3636
Expression<Action<IFullMappingInlineConfigurator<TSource, TTarget>>>[] configurations)
3737
{
38-
// TODO: Include projection mapping plans:
3938
return new MappingPlanSet(
4039
_mapperContext
4140
.RuleSets
4241
.All
43-
.Except(new[] { _mapperContext.RuleSets.Project })
42+
.Where(ruleSet => ruleSet != _mapperContext.RuleSets.Project)
4443
.Select(rs => GetMappingPlan(rs, configurations))
4544
.ToArray());
4645
}

AgileMapper/Configuration/DerivedTypePair.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
using System;
44
using System.Globalization;
5-
using System.Linq;
5+
using Extensions.Internal;
66
using Members;
77
using NetStandardPolyfills;
88
using ReadableExpressions.Extensions;

AgileMapper/Configuration/DerivedTypePairSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void Add(DerivedTypePair typePair)
4545

4646
private static void RemoveConflictingPairIfAppropriate(
4747
DerivedTypePair typePair,
48-
ICollection<DerivedTypePair> typePairs)
48+
IList<DerivedTypePair> typePairs)
4949
{
5050
if (typePair.HasConfiguredCondition)
5151
{

AgileMapper/Configuration/Dictionaries/DictionarySettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public string GetMemberKeyOrNull(Member member, IMemberMapperData mapperData)
9494
=> FindKeyOrNull(_configuredMemberKeys, member, mapperData)?.Key;
9595

9696
private static CustomDictionaryKey FindKeyOrNull(
97-
IEnumerable<CustomDictionaryKey> keys,
97+
IList<CustomDictionaryKey> keys,
9898
Member member,
9999
IMemberMapperData mapperData)
100100
=> keys.FirstOrDefault(k => k.AppliesTo(member, mapperData));
@@ -121,7 +121,7 @@ public void Add(ElementKeyPartFactory keyPartFactory)
121121

122122
private static void ThrowIfConflictingKeyPartFactoryExists<TKeyPartFactory>(
123123
TKeyPartFactory factory,
124-
ICollection<TKeyPartFactory> existingFactories)
124+
IList<TKeyPartFactory> existingFactories)
125125
where TKeyPartFactory : DictionaryKeyPartFactoryBase
126126
{
127127
if (existingFactories.HasOne())

AgileMapper/Configuration/Dictionaries/ElementKeyPartFactory.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ public static ElementKeyPartFactory UnderscoredIndexForTargetDynamics(MapperCont
6060
}
6161

6262
public static ElementKeyPartFactory SquareBracketedIndex(MapperContext mapperContext)
63-
=> new ElementKeyPartFactory("[", "]", MappingConfigInfo.AllRuleSetsSourceTypesAndTargetTypes(mapperContext));
63+
{
64+
return new ElementKeyPartFactory(
65+
"[", "]",
66+
MappingConfigInfo.AllRuleSetsAndSourceTypes(mapperContext).ForAllTargetTypes());
67+
}
6468

6569
private static readonly Regex _patternMatcher = new Regex("^(?<Prefix>[^i]*)i{1}(?<Suffix>[^i]*)$"
6670
#if !NET_STANDARD

AgileMapper/Configuration/Dictionaries/JoiningNameFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static JoiningNameFactory UnderscoredForTargetDynamics(MapperContext mapp
5757
}
5858

5959
public static JoiningNameFactory Dotted(MapperContext mapperContext)
60-
=> ForDefault(".", MappingConfigInfo.AllRuleSetsSourceTypesAndTargetTypes(mapperContext));
60+
=> ForDefault(".", MappingConfigInfo.AllRuleSetsSourceTypesAndTargetTypes);
6161

6262
public static JoiningNameFactory Flattened(MappingConfigInfo configInfo)
6363
=> For(string.Empty, configInfo);

AgileMapper/Configuration/MappedObjectCachingSettings.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ internal class MappedObjectCachingSettings : UserConfiguredItemBase
77
#region Singleton Instances
88

99
public static readonly MappedObjectCachingSettings CacheAll =
10-
new MappedObjectCachingSettings(ForAllMappings(MapperContext.Default), cache: true);
10+
new MappedObjectCachingSettings(MappingConfigInfo.AllRuleSetsSourceTypesAndTargetTypes, cache: true);
1111

1212
public static readonly MappedObjectCachingSettings CacheNone =
13-
new MappedObjectCachingSettings(ForAllMappings(MapperContext.Default), cache: false);
14-
15-
private static MappingConfigInfo ForAllMappings(MapperContext mapperContext)
16-
=> MappingConfigInfo.AllRuleSetsSourceTypesAndTargetTypes(mapperContext);
13+
new MappedObjectCachingSettings(MappingConfigInfo.AllRuleSetsSourceTypesAndTargetTypes, cache: false);
1714

1815
#endregion
1916

0 commit comments

Comments
 (0)