I have a class I want to implement, but there is a lot of conditional logic so I decided to implement a builder(like) pattern. These setters will pretty much only be flags to set
private class MockBuilder
{
private bool _flag1 = false;
private bool _flag2 = false;
// arbitrarily long amount of flags here
public MockBuilder()
{
}
public void DoFlag1(bool value = true)
{
_flag1 = value;
}
public void DoFlag2(bool value = true)
{
_flag2 = value;
}
public builtObject Build()
{
// Build with current flags
}
}
Long story short, I looked into default params for setters and some questions like: c#: getter/setter and wondering if there was a more "C#" way to do this, something along the lines of
public bool flag1 { get; set(value = true); }
The end goal being able to call the builder like so
var object = new MockBuilder();
builder
.flag1()
.flag3()
// etc...
.generate();
Does C# implement some sort of default value for setters? Is this a good use of the builder pattern? Should I be using a different pattern all together?