File tree Expand file tree Collapse file tree 2 files changed +71
-14
lines changed Expand file tree Collapse file tree 2 files changed +71
-14
lines changed Original file line number Diff line number Diff line change 1+ // Non-nullable member is uninitialized
2+ #pragma warning disable CS8618
3+ // ReSharper disable All
4+
5+ // Example from https://stackoverflow.com/questions/59021513/using-fluent-interface-with-builder-pattern.
6+
7+ using M31 . FluentApi . Attributes ;
8+
9+ namespace ExampleProject ;
10+
11+ [ FluentApi ]
12+ public class Employee
13+ {
14+ [ FluentMember ( 0 ) ]
15+ public string Name { get ; private set ; }
16+
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 ; }
22+ }
23+
24+ [ FluentApi ]
25+ public class Phone
26+ {
27+ [ FluentMember ( 0 ) ]
28+ public string Number { get ; private set ; }
29+
30+ [ FluentMember ( 1 ) ]
31+ public string Usage { get ; private set ; }
32+ }
33+
34+ [ FluentApi ]
35+ public class Job
36+ {
37+ [ FluentMember ( 0 ) ]
38+ public string CompanyName { get ; private set ; }
39+
40+ [ FluentMember ( 1 ) ]
41+ public int Salary { get ; private set ; }
42+ }
Original file line number Diff line number Diff line change 6767
6868Console . WriteLine ( hashCode ) ;
6969
70- // Node
71- //
72-
73- Node < int > tree = CreateTree < int > . Root ( 8 )
74- . Left ( 3 , n => n
75- . Left ( 1 )
76- . Right ( 6 ) )
77- . Right ( 10 , n => n
78- . LeftNull ( )
79- . Right ( 14 ) ) ;
80-
81- Console . WriteLine ( JsonSerializer . Serialize ( tree ) ) ;
82-
8370// Docker file
8471//
8572// Example from https://mitesh1612.github.io/blog/2021/08/11/how-to-design-fluent-api.
9481 . WithCommand ( "npm start" )
9582 . ToString ( ) ;
9683
97- Console . WriteLine ( dockerFile ) ;
84+ Console . WriteLine ( dockerFile ) ;
85+
86+ // Employee
87+ //
88+ // Example from https://stackoverflow.com/questions/59021513/using-fluent-interface-with-builder-pattern.
89+ //
90+
91+ Employee employee = CreateEmployee
92+ . WithName ( "My Name" )
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 ) ) ;
98+
99+ Console . WriteLine ( JsonSerializer . Serialize ( employee ) ) ;
100+
101+ // Node
102+ //
103+
104+ Node < int > tree = CreateTree < int > . Root ( 8 )
105+ . Left ( 3 , n => n
106+ . Left ( 1 )
107+ . Right ( 6 ) )
108+ . Right ( 10 , n => n
109+ . LeftNull ( )
110+ . Right ( 14 ) ) ;
111+
112+ Console . WriteLine ( JsonSerializer . Serialize ( tree ) ) ;
You can’t perform that action at this time.
0 commit comments