Fluent conditional exection of actions
$ dotnet add package LSL.ExecuteIfA simple library to provide fluent conditional execution of a delegate that gets given the target to do with as it pleases.
var values = new List<int> { 1, 2 };
values.ExecuteIf(() => true, v => v.Add(3))
.Add(22); // the list was returned so we can call add
// values will now be { 1, 2, 3, 22 }
var values = new List<int> { 1, 2 };
values.ExecuteIf(true, v => v.Add(3))
.Add(22); // the list was returned so we can call add
// values will now be { 1, 2, 3, 22 }
var values = new List<int> { 1, 2 };
values.ExecuteIf(false, v => v.Add(3), v => v.Add(5))
.Add(22); // the list was returned so we can call Add(5)
// values will now be { 1, 2, 5, 22 }
This library also provides a convenience extension method to configure a source object fluently.
var values = new List<int> { 1, 2 };
values.ConfigureWith(v => v.Add(5));
// values will now be { 1, 2, 5 }