Skip to content

Commit f149a39

Browse files
committed
Switching from MappingTypes.Fixed() to MappingTypes<>.Fixed
1 parent 9c5de93 commit f149a39

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

AgileMapper/MappingExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private ObjectMappingData<TSource, TTarget> CreateTypedRootMappingData<TTarget>(
6868
_source,
6969
target,
7070
null, // <- No enumerable index because we're at the root
71-
new RootObjectMapperKey(MappingTypes.Fixed<TSource, TTarget>(), this),
71+
new RootObjectMapperKey(MappingTypes<TSource, TTarget>.Fixed, this),
7272
this,
7373
parent: null);
7474
}

AgileMapper/Members/MappingTypes.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace AgileObjects.AgileMapper.Members
66

77
internal class MappingTypes
88
{
9-
private MappingTypes(
9+
public MappingTypes(
1010
Type sourceType,
1111
Type targetType,
1212
bool runtimeTypesAreTheSame,
@@ -20,13 +20,11 @@ private MappingTypes(
2020

2121
#region Factory Method
2222

23-
public static MappingTypes Fixed<TSource, TTarget>() => MappingTypesCache<TSource, TTarget>.Instance;
24-
2523
public static MappingTypes For<TSource, TTarget>(TSource source, TTarget target)
2624
{
27-
if (MappingTypesCache<TSource, TTarget>.SkipTypesCheck)
25+
if (MappingTypes<TSource, TTarget>.SkipTypesCheck)
2826
{
29-
return Fixed<TSource, TTarget>();
27+
return MappingTypes<TSource, TTarget>.Fixed;
3028
}
3129

3230
var runtimeSourceTypeNeeded = TypeInfo<TSource>.RuntimeTypeNeeded;
@@ -78,7 +76,7 @@ public static MappingTypes For<TSource, TTarget>(TSource source, TTarget target)
7876

7977
if (!runtimeTypesNeeded)
8078
{
81-
return Fixed<TSource, TTarget>();
79+
return MappingTypes<TSource, TTarget>.Fixed;
8280
}
8381

8482
var isEnumerable = TypeInfo<TTarget>.IsEnumerable ||
@@ -121,17 +119,17 @@ public MappingTypes WithTypes<TNewSource, TNewTarget>()
121119
RuntimeTypesAreTheSame,
122120
IsEnumerable);
123121
}
122+
}
124123

125-
private static class MappingTypesCache<TSource, TTarget>
126-
{
127-
public static readonly bool SkipTypesCheck =
128-
!(TypeInfo<TSource>.RuntimeTypeNeeded || TypeInfo<TTarget>.RuntimeTypeNeeded);
129-
130-
public static readonly MappingTypes Instance = new MappingTypes(
131-
typeof(TSource),
132-
typeof(TTarget),
133-
true, // <- runtimeTypesAreTheSame
134-
TypeInfo<TTarget>.IsEnumerable);
135-
}
124+
internal static class MappingTypes<TSource, TTarget>
125+
{
126+
public static readonly bool SkipTypesCheck =
127+
!(TypeInfo<TSource>.RuntimeTypeNeeded || TypeInfo<TTarget>.RuntimeTypeNeeded);
128+
129+
public static readonly MappingTypes Fixed = new MappingTypes(
130+
typeof(TSource),
131+
typeof(TTarget),
132+
true, // <- runtimeTypesAreTheSame
133+
TypeInfo<TTarget>.IsEnumerable);
136134
}
137135
}

AgileMapper/ObjectPopulation/MappingDataFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static ObjectMappingData<TSource, TTarget> ForChild<TSource, TTarget>(
2525
var mapperKey = new ChildObjectMapperKey(
2626
targetMemberRegistrationName,
2727
dataSourceIndex,
28-
MappingTypes.Fixed<TSource, TTarget>());
28+
MappingTypes<TSource, TTarget>.Fixed);
2929

3030
var mappingData = CreateMappingData(source, target, enumerableIndex, mapperKey, parent);
3131

@@ -53,7 +53,7 @@ public static ObjectMappingData<TSourceElement, TTargetElement> ForElement<TSour
5353
int enumerableIndex,
5454
IObjectMappingDataUntyped parent)
5555
{
56-
var mapperKey = new ElementObjectMapperKey(MappingTypes.Fixed<TSourceElement, TTargetElement>());
56+
var mapperKey = new ElementObjectMapperKey(MappingTypes<TSourceElement, TTargetElement>.Fixed);
5757

5858
var mappingData = CreateMappingData(sourceElement, targetElement, enumerableIndex, mapperKey, parent);
5959

0 commit comments

Comments
 (0)