-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a possibility to retrieve the Maybe's value where a default value is returned for the none-Case #65
Comments
This would also allow us to have readonly properties set by a public class XmlTestOutputCompareAssertParameter
{
public XmlTestOutputCompareAssertParameter(
Maybe<string> aMaybeFileExtensionPattern = default)
{
aMaybeFileExtensionPattern.Do(aFileExtensionPattern => this.FileExtensionPattern = aFileExtensionPattern);
}
// Bad example: needs a private setter
public string FileExtensionPattern { get; private set; } = ".txt";
} public class XmlTestOutputCompareAssertParameter
{
public XmlTestOutputCompareAssertParameter(
Maybe<string> aMaybeFileExtensionPattern = default)
{
this.FileExtensionPattern = aMaybeFileExtensionPattern.ValueOrDefault(".txt");
}
// Good example: Private setter isn't needed
// Bonus: Default value and initialization via c'tor are together in one place.
public string FileExtensionPattern { get; }
} Overall, code would be cleaner as the Maybe-Pattern wouldn't enforce readonly properties to become properties with private setters when initializable via c'tor. |
@stefan-lindegger Opinions? |
offline discussion with @stefan-lindegger:
We also would like this to be a task for someone within BBT who hasn't had the chance to gather experience with GitHub yet to get their feet wet. |
…method renamed to ValueOrException.
…method renamed to ValueOrException.
(GH-65) ValueOrDefault method added. ThrowExceptionIfNone method renamed.
I'm thinking about the case where a
Maybe<T>
is used as a method parameter and a default value is known for the behavior in this method, for example:This could be made a lot simpler with the following method wich should be added:
The text was updated successfully, but these errors were encountered: