-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCreateStudent.g.cs
209 lines (170 loc) · 6.11 KB
/
CreateStudent.g.cs
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// <auto-generated/>
// This code was generated by the library M31.FluentAPI.
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#nullable enable
using System;
using System.Collections.Generic;
using System.Reflection;
namespace M31.FluentApi.Tests.CodeGeneration.TestClasses.StudentClass;
public class CreateStudent :
CreateStudent.ICreateStudent,
CreateStudent.INamed,
CreateStudent.IOfAgeBornOn,
CreateStudent.IInSemester,
CreateStudent.ILivingIn,
CreateStudent.IWhoIsHappy,
CreateStudent.IWhoseFriendsAre
{
private readonly Student student;
private static readonly PropertyInfo firstNamePropertyInfo;
private static readonly PropertyInfo lastNamePropertyInfo;
private static readonly PropertyInfo agePropertyInfo;
private static readonly MethodInfo bornOnMethodInfo;
private static readonly PropertyInfo semesterPropertyInfo;
private static readonly PropertyInfo cityPropertyInfo;
private static readonly PropertyInfo isHappyPropertyInfo;
private static readonly PropertyInfo friendsPropertyInfo;
static CreateStudent()
{
firstNamePropertyInfo = typeof(Student).GetProperty("FirstName", BindingFlags.Instance | BindingFlags.Public)!;
lastNamePropertyInfo = typeof(Student).GetProperty("LastName", BindingFlags.Instance | BindingFlags.Public)!;
agePropertyInfo = typeof(Student).GetProperty("Age", BindingFlags.Instance | BindingFlags.Public)!;
bornOnMethodInfo = typeof(Student).GetMethod(
"BornOn",
0,
BindingFlags.Instance | BindingFlags.NonPublic,
null,
new Type[] { typeof(System.DateOnly) },
null)!;
semesterPropertyInfo = typeof(Student).GetProperty("Semester", BindingFlags.Instance | BindingFlags.Public)!;
cityPropertyInfo = typeof(Student).GetProperty("City", BindingFlags.Instance | BindingFlags.Public)!;
isHappyPropertyInfo = typeof(Student).GetProperty("IsHappy", BindingFlags.Instance | BindingFlags.Public)!;
friendsPropertyInfo = typeof(Student).GetProperty("Friends", BindingFlags.Instance | BindingFlags.Public)!;
}
private CreateStudent()
{
student = new Student();
}
public static ICreateStudent InitialStep()
{
return new CreateStudent();
}
public static IOfAgeBornOn Named(string firstName, string lastName)
{
CreateStudent createStudent = new CreateStudent();
CreateStudent.firstNamePropertyInfo.SetValue(createStudent.student, firstName);
CreateStudent.lastNamePropertyInfo.SetValue(createStudent.student, lastName);
return createStudent;
}
IOfAgeBornOn INamed.Named(string firstName, string lastName)
{
CreateStudent.firstNamePropertyInfo.SetValue(student, firstName);
CreateStudent.lastNamePropertyInfo.SetValue(student, lastName);
return this;
}
IInSemester IOfAgeBornOn.OfAge(int age)
{
CreateStudent.agePropertyInfo.SetValue(student, age);
return this;
}
IInSemester IOfAgeBornOn.BornOn(System.DateOnly dateOfBirth)
{
CreateStudent.bornOnMethodInfo.Invoke(student, new object?[] { dateOfBirth });
return this;
}
ILivingIn IInSemester.InSemester(int semester)
{
CreateStudent.semesterPropertyInfo.SetValue(student, semester);
return this;
}
ILivingIn IInSemester.WhoStartsUniversity()
{
return this;
}
IWhoIsHappy ILivingIn.LivingIn(string? city)
{
CreateStudent.cityPropertyInfo.SetValue(student, city);
return this;
}
IWhoIsHappy ILivingIn.LivingInBoston()
{
return this;
}
IWhoIsHappy ILivingIn.InUnknownCity()
{
CreateStudent.cityPropertyInfo.SetValue(student, null);
return this;
}
IWhoseFriendsAre IWhoIsHappy.WhoIsHappy(bool? isHappy)
{
CreateStudent.isHappyPropertyInfo.SetValue(student, isHappy);
return this;
}
IWhoseFriendsAre IWhoIsHappy.WhoIsSad()
{
CreateStudent.isHappyPropertyInfo.SetValue(student, false);
return this;
}
IWhoseFriendsAre IWhoIsHappy.WithUnknownMood()
{
CreateStudent.isHappyPropertyInfo.SetValue(student, null);
return this;
}
Student IWhoseFriendsAre.WhoseFriendsAre(System.Collections.Generic.IReadOnlyCollection<string> friends)
{
CreateStudent.friendsPropertyInfo.SetValue(student, friends);
return student;
}
Student IWhoseFriendsAre.WhoseFriendsAre(params string[] friends)
{
CreateStudent.friendsPropertyInfo.SetValue(student, friends);
return student;
}
Student IWhoseFriendsAre.WhoseFriendIs(string friend)
{
CreateStudent.friendsPropertyInfo.SetValue(student, new string[1]{ friend });
return student;
}
Student IWhoseFriendsAre.WhoHasNoFriends()
{
CreateStudent.friendsPropertyInfo.SetValue(student, new string[0]);
return student;
}
public interface ICreateStudent : INamed
{
}
public interface INamed
{
IOfAgeBornOn Named(string firstName, string lastName);
}
public interface IOfAgeBornOn
{
IInSemester OfAge(int age);
IInSemester BornOn(System.DateOnly dateOfBirth);
}
public interface IInSemester
{
ILivingIn InSemester(int semester);
ILivingIn WhoStartsUniversity();
}
public interface ILivingIn
{
IWhoIsHappy LivingIn(string? city);
IWhoIsHappy LivingInBoston();
IWhoIsHappy InUnknownCity();
}
public interface IWhoIsHappy
{
IWhoseFriendsAre WhoIsHappy(bool? isHappy = true);
IWhoseFriendsAre WhoIsSad();
IWhoseFriendsAre WithUnknownMood();
}
public interface IWhoseFriendsAre
{
Student WhoseFriendsAre(System.Collections.Generic.IReadOnlyCollection<string> friends);
Student WhoseFriendsAre(params string[] friends);
Student WhoseFriendIs(string friend);
Student WhoHasNoFriends();
}
}