diff --git a/README.md b/README.md index 9ba9f60..d312204 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/ExampleProject/OrderArbitrarySteps.cs b/src/ExampleProject/OrderArbitrarySteps.cs index 1f047a7..645c75b 100644 --- a/src/ExampleProject/OrderArbitrarySteps.cs +++ b/src/ExampleProject/OrderArbitrarySteps.cs @@ -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()