-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvement default value handling (#107)
- Loading branch information
Showing
7 changed files
with
47 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace Sharprompt.Internal | ||
{ | ||
internal readonly struct Optional<T> | ||
{ | ||
public Optional(T value) | ||
{ | ||
HasValue = true; | ||
Value = value; | ||
} | ||
|
||
public bool HasValue { get; } | ||
|
||
public T Value { get; } | ||
|
||
public static implicit operator T(Optional<T> optional) => optional.Value; | ||
|
||
public static readonly Optional<T> Empty = new Optional<T>(); | ||
|
||
public static Optional<T> Create(T value) | ||
{ | ||
return value == null ? Empty : new Optional<T>(value); | ||
} | ||
|
||
public static Optional<T> Create(object value) | ||
{ | ||
return value == null ? Empty : new Optional<T>((T)value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters