Skip to content

Commit 7e808fd

Browse files
committed
feat(ExampleProject): Employee example
1 parent d2a8f8c commit 7e808fd

File tree

2 files changed

+11
-34
lines changed

2 files changed

+11
-34
lines changed

src/ExampleProject/Employee.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,11 @@ public class Employee
1414
[FluentMember(0)]
1515
public string Name { get; private set; }
1616

17-
public List<Job> Jobs { get; private set; } = new List<Job>();
18-
19-
public List<Phone> Phones { get; private set; } = new List<Phone>();
20-
21-
[FluentMethod(1)]
22-
[FluentContinueWith(1)]
23-
public void HavingJob(Func<CreateJob.ICreateJob, Job> createJob)
24-
{
25-
Jobs.Add(createJob(CreateJob.InitialStep()));
26-
}
27-
28-
[FluentMethod(1)]
29-
[FluentContinueWith(1)]
30-
public void HavingPhone(Func<CreatePhone.ICreatePhone, Phone> createPhone)
31-
{
32-
Phones.Add(createPhone(CreatePhone.InitialStep()));
33-
}
34-
35-
[FluentMethod(1)]
36-
private void Build()
37-
{
38-
}
17+
[FluentCollection(1, "Phone")]
18+
public List<Phone> Phones { get; private set; }
19+
20+
[FluentCollection(2, "Job")]
21+
public List<Job> Jobs { get; private set; }
3922
}
4023

4124
[FluentApi]

src/ExampleProject/Program.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,18 @@
8383

8484
Console.WriteLine(dockerFile);
8585

86-
// Person
86+
// Employee
8787
//
8888
// Example from https://stackoverflow.com/questions/59021513/using-fluent-interface-with-builder-pattern.
8989
//
9090

9191
Employee employee = CreateEmployee
9292
.WithName("My Name")
93-
.HavingPhone(p => p
94-
.WithNumber("222-222-2222")
95-
.WithUsage("CELL"))
96-
.HavingJob(j => j
97-
.WithCompanyName("First Company")
98-
.WithSalary(100))
99-
.HavingJob(j => j
100-
.WithCompanyName("Second Company")
101-
.WithSalary(200)
102-
)
103-
.Build();
93+
.WithPhone(
94+
p => p.WithNumber("222-222-2222").WithUsage("CELL"))
95+
.WithJobs(
96+
j => j.WithCompanyName("First Company").WithSalary(100),
97+
j => j.WithCompanyName("Second Company").WithSalary(200));
10498

10599
Console.WriteLine(JsonSerializer.Serialize(employee));
106100

0 commit comments

Comments
 (0)