3 ms·
I've been structuring more and more of my code with patterns like: bool SomeProperty { get; set; } = false; string SomeValue => SomeProperty == true ? Some
by bob1029 4y ago
I've been structuring more and more of my code with patterns like:
bool SomeProperty { get; set; } = false;
string SomeValue => SomeProperty == true ? SomeValueA : SomeValueB;
string SomeValueA => "A";
string SomeValueB => SqliteConnection.ExecuteScalar<string>("SELECT 'B'");
string SomeDescription => SomeProperty switch
{
false => "Extended description for false",
true => "Extended description for true"
}
string Output =>
@$"Result: {SomeValue}
Description: {SomeDescription}";
Combine with language features like LINQ and you can do an incredible amount of damage before you have to take out a proper method body.
I've caught a LOT of bugs converting method bodies to expressions like this.
- karmakaze 4y agoIt's confusing in the context of FP that your example uses SomeX when referring to non-optional types.