-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapsterConfig.cs
More file actions
50 lines (44 loc) · 1.74 KB
/
MapsterConfig.cs
File metadata and controls
50 lines (44 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Mapster;
namespace Linqraft.Benchmark;
/// <summary>
/// Mapster configuration for benchmark.
/// Configures type mappings for entity to DTO projections.
/// </summary>
public static class MapsterConfig
{
private static bool _configured;
/// <summary>
/// Configures Mapster type mappings.
/// Call this once before using Mapster projections.
/// </summary>
public static void Configure()
{
if (_configured)
return;
// Configure SampleClass to ManualSampleClassDto mapping
TypeAdapterConfig<SampleClass, ManualSampleClassDto>
.NewConfig()
.Map(dest => dest.Child2Id, src => src.Child2 != null ? src.Child2.Id : (int?)null)
.Map(dest => dest.Child2Quux, src => src.Child2 != null ? src.Child2.Quux : null)
.Map(dest => dest.Child3Id, src => src.Child3.Id)
.Map(dest => dest.Child3Corge, src => src.Child3.Corge)
.Map(
dest => dest.Child3ChildId,
src =>
src.Child3 != null && src.Child3.Child != null
? src.Child3.Child.Id
: (int?)null
)
.Map(
dest => dest.Child3ChildGrault,
src =>
src.Child3 != null && src.Child3.Child != null ? src.Child3.Child.Grault : null
);
// Configure SampleChildClass to ManualSampleChildDto mapping
TypeAdapterConfig<SampleChildClass, ManualSampleChildDto>
.NewConfig()
.Map(dest => dest.ChildId, src => src.Child != null ? src.Child.Id : (int?)null)
.Map(dest => dest.ChildQux, src => src.Child != null ? src.Child.Qux : null);
_configured = true;
}
}