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
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,58 @@ university.AddStudent(s => s.Named("Alice", "King").OfAge(22)...);
```

Note that if you want to set a member of a Fluent API class, you can simply use `FluentMember` or `FluentCollection` instead of the pattern above.


### Make everything optional

There are two ways to make all fields, properties, and methods optional in your fluent API. If the initialization order matters for your use case, use the following approach:

```cs
[FluentApi]
public class Student
{
[FluentMember(0)]
[FluentSkippable]
public string? FirstName { get; private set; }

[FluentMember(1)]
[FluentSkippable]
public string? LastName { get; private set; }

[FluentMember(2)]
[FluentSkippable]
public int? Age { get; private set; }

[FluentMethod(3)]
public void Build()
{
}
}
```

If the initialization order does not matter, you can simplify the configuration as follows:

```cs
public class Student
{
[FluentMember(0)]
[FluentContinueWith(0)]
public string? FirstName { get; private set; }

[FluentMember(0)]
[FluentContinueWith(0)]
public string? LastName { get; private set; }

[FluentMember(0)]
[FluentContinueWith(0)]
public int? Age { get; private set; }

[FluentMethod(0)]
public void Build()
{
}
}
```


## Problems with the IDE
Expand Down
10 changes: 5 additions & 5 deletions src/ExampleProject/OrderArbitrarySteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ public class Address2
{
[FluentMember(0, "{Name}")]
[FluentContinueWith(0)]
public string Street { get; private set; }
public string? Street { get; private set; }

[FluentMember(0, "{Name}")]
[FluentContinueWith(0)]
public string City { get; private set; }
public string? City { get; private set; }

[FluentMember(0, "{Name}")]
[FluentContinueWith(0)]
public string Zip { get; private set; }
public string? Zip { get; private set; }

[FluentMember(0, "{Name}")]
[FluentContinueWith(0)]
public string State { get; private set; }
public string? State { get; private set; }

[FluentMember(0, "{Name}")]
[FluentContinueWith(0)]
public string Country { get; private set; }
public string? Country { get; private set; }

[FluentMethod(0)]
private void Build()
Expand Down
Loading