-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiParamMappers.cs
More file actions
138 lines (120 loc) · 6.33 KB
/
Copy pathMultiParamMappers.cs
File metadata and controls
138 lines (120 loc) · 6.33 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
namespace AlephMapper.IntegrationTests;
// ──────────────────────────────────────────────────────────────────
// 1. Expressive mapper with multi-parameter helper inlining
// ──────────────────────────────────────────────────────────────────
[Expressive(NullConditionalRewrite = NullConditionalRewrite.Rewrite)]
public static partial class MultiParamEmployeeMapper
{
// Two-parameter helper: concatenate first + last
public static string FormatName(string first, string last) =>
first + " " + last;
// Three-parameter helper: build a formatted address string
public static string FormatAddress(string street, string city, string country) =>
street + ", " + city + ", " + country;
// Mixed-type two-parameter helper: arithmetic
public static int YearsSince(int startYear, int currentYear) =>
currentYear - startYear;
// Nested multi-param: calls FormatName internally
public static string FormatNameWithEmail(string first, string last, string email) =>
FormatName(first, last) + " <" + email + ">";
// Single-param helper to ensure mixing single + multi works
public static string GetDepartmentName(Employee employee) =>
employee.Department?.Name ?? "Unassigned";
// ── Expression mapping that uses all the above helpers ──
[Expressive]
public static EmployeeDto MapToDto(Employee employee) => new()
{
Id = employee.Id,
FullName = FormatName(employee.FirstName, employee.LastName),
Email = employee.Email,
DepartmentName = GetDepartmentName(employee),
IsActive = employee.IsActive
};
// Mapping that exercises three-parameter helper
[Expressive]
public static EmployeeSimpleDto MapToSimpleDto(Employee employee) => new()
{
Id = employee.Id,
FirstName = employee.FirstName,
LastName = employee.LastName,
Email = employee.Email,
DepartmentName = GetDepartmentName(employee)
};
// Mapping that exercises nested multi-param helper
[Expressive]
public static EmployeeDto MapToDtoWithEmail(Employee employee) => new()
{
Id = employee.Id,
FullName = FormatNameWithEmail(employee.FirstName, employee.LastName, employee.Email),
Email = employee.Email,
DepartmentName = GetDepartmentName(employee),
IsActive = employee.IsActive
};
}
// ──────────────────────────────────────────────────────────────────
// 2. Named-argument mapper — arguments passed out of order
// ──────────────────────────────────────────────────────────────────
[Expressive(NullConditionalRewrite = NullConditionalRewrite.Rewrite)]
public static partial class NamedArgEmployeeMapper
{
public static string FormatName(string first, string last) =>
first + " " + last;
public static string GetDepartmentName(Employee employee) =>
employee.Department?.Name ?? "Unassigned";
[Expressive]
public static EmployeeDto MapToDto(Employee employee) => new()
{
Id = employee.Id,
// Named arguments in reversed order — should still inline correctly
FullName = FormatName(last: employee.LastName, first: employee.FirstName),
Email = employee.Email,
DepartmentName = GetDepartmentName(employee),
IsActive = employee.IsActive
};
}
// ──────────────────────────────────────────────────────────────────
// 3. Updatable mapper with multi-param helpers
// (exercises the BinaryExpressionSyntax spacing fix)
// ──────────────────────────────────────────────────────────────────
[Expressive(NullConditionalRewrite = NullConditionalRewrite.Rewrite)]
public static partial class MultiParamUpdatableMapper
{
public static string FormatName(string first, string last) =>
first + " " + last;
public static int YearsSince(int startYear, int currentYear) =>
currentYear - startYear;
public static string GetDepartmentName(Employee employee) =>
employee.Department?.Name ?? "Unassigned";
[Updatable]
public static EmployeeDto MapToDto(Employee employee) => new()
{
Id = employee.Id,
FullName = FormatName(employee.FirstName, employee.LastName),
Email = employee.Email,
DepartmentName = GetDepartmentName(employee),
IsActive = employee.IsActive
};
}
// ──────────────────────────────────────────────────────────────────
// 4. Multi-parameter [Expressive] method itself
// Generates Expression<Func<Employee, int, EmployeeDto>>
// ──────────────────────────────────────────────────────────────────
[Expressive(NullConditionalRewrite = NullConditionalRewrite.Rewrite)]
public static partial class MultiParamExpressiveMapper
{
public static string FormatName(string first, string last) =>
first + " " + last;
public static string GetDepartmentName(Employee employee) =>
employee.Department?.Name ?? "Unassigned";
// The [Expressive] method ITSELF takes two parameters
[Expressive]
public static EmployeeDto MapWithYear(Employee employee, int currentYear) => new()
{
Id = employee.Id,
FullName = FormatName(employee.FirstName, employee.LastName),
Email = employee.Email,
DepartmentName = GetDepartmentName(employee),
IsActive = employee.IsActive,
YearsOfExperience = currentYear - 2020 // simple arithmetic with the extra param
};
}