Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/ExampleProject/Employee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Non-nullable member is uninitialized
#pragma warning disable CS8618
// ReSharper disable All

// Example from https://stackoverflow.com/questions/59021513/using-fluent-interface-with-builder-pattern.

using M31.FluentApi.Attributes;

namespace ExampleProject;

[FluentApi]
public class Employee
{
[FluentMember(0)]
public string Name { get; private set; }

[FluentCollection(1, "Phone")]
public List<Phone> Phones { get; private set; }

[FluentCollection(2, "Job")]
public List<Job> Jobs { get; private set; }
}

[FluentApi]
public class Phone
{
[FluentMember(0)]
public string Number { get; private set; }

[FluentMember(1)]
public string Usage { get; private set; }
}

[FluentApi]
public class Job
{
[FluentMember(0)]
public string CompanyName { get; private set; }

[FluentMember(1)]
public int Salary { get; private set; }
}
43 changes: 29 additions & 14 deletions src/ExampleProject/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@

Console.WriteLine(hashCode);

// Node
//

Node<int> tree = CreateTree<int>.Root(8)
.Left(3, n => n
.Left(1)
.Right(6))
.Right(10, n => n
.LeftNull()
.Right(14));

Console.WriteLine(JsonSerializer.Serialize(tree));

// Docker file
//
// Example from https://mitesh1612.github.io/blog/2021/08/11/how-to-design-fluent-api.
Expand All @@ -94,4 +81,32 @@
.WithCommand("npm start")
.ToString();

Console.WriteLine(dockerFile);
Console.WriteLine(dockerFile);

// Employee
//
// Example from https://stackoverflow.com/questions/59021513/using-fluent-interface-with-builder-pattern.
//

Employee employee = CreateEmployee
.WithName("My Name")
.WithPhone(
p => p.WithNumber("222-222-2222").WithUsage("CELL"))
.WithJobs(
j => j.WithCompanyName("First Company").WithSalary(100),
j => j.WithCompanyName("Second Company").WithSalary(200));

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

// Node
//

Node<int> tree = CreateTree<int>.Root(8)
.Left(3, n => n
.Left(1)
.Right(6))
.Right(10, n => n
.LeftNull()
.Right(14));

Console.WriteLine(JsonSerializer.Serialize(tree));