-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleMappers.cs
More file actions
82 lines (68 loc) · 2.57 KB
/
Copy pathSimpleMappers.cs
File metadata and controls
82 lines (68 loc) · 2.57 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
namespace AlephMapper.IntegrationTests;
[Expressive(NullConditionalRewrite = NullConditionalRewrite.Rewrite)]
public static partial class SimpleEmployeeMapper
{
// Basic property mapping
public static string GetFullName(Employee employee) =>
$"{employee.FirstName} {employee.LastName}";
public static string GetEmail(Employee employee) =>
employee.Email;
// Null conditional operators
public static string GetDepartmentName(Employee employee) =>
employee.Department?.Name ?? "No Department";
public static string GetManagerName(Employee employee) =>
employee.Manager?.FirstName ?? "No Manager";
public static string GetPhone(Employee employee) =>
employee.Profile?.Phone ?? "No Phone";
// Simple boolean expressions
public static bool HasProfile(Employee employee) =>
employee.Profile != null;
public static bool IsActive(Employee employee) =>
employee.IsActive;
// Collection count
public static int GetAddressCount(Employee employee) =>
employee.Addresses.Count;
public static EmployeeSimpleDto MapToSimpleDto(Employee employee) => new()
{
Id = employee.Id,
FirstName = employee.FirstName,
LastName = employee.LastName,
Email = GetEmail(employee),
DepartmentName = GetDepartmentName(employee)
};
}
[Expressive(NullConditionalRewrite = NullConditionalRewrite.Ignore)]
public static partial class SimpleIgnoreMapper
{
public static string GetFullName(Employee employee) =>
$"{employee.FirstName} {employee.LastName}";
public static string GetDepartmentName(Employee employee) =>
employee.Department?.Name ?? "No Department";
public static EmployeeSimpleDto MapToSimpleDto(Employee employee) => new()
{
Id = employee.Id,
FirstName = employee.FirstName,
LastName = employee.LastName,
Email = employee.Email,
DepartmentName = GetDepartmentName(employee)
};
}
[Updatable]
public static partial class SimpleUpdateMapper
{
public static EmployeeSimpleDto MapToSimpleDto(Employee employee) => new()
{
Id = employee.Id,
FirstName = employee.FirstName,
LastName = employee.LastName,
Email = employee.Email,
DepartmentName = employee.Department?.Name ?? "No Department"
};
public static DepartmentUpdateDto MapToDepartmentDto(Department department) => new()
{
Id = department.Id,
Name = department.Name,
Description = department.Description,
IsActive = department.IsActive
};
}