Last active
December 19, 2015 13:19
-
-
Save UberMouse/5961667 to your computer and use it in GitHub Desktop.
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
public class Option<T> | |
{ | |
public readonly T Value; | |
public bool HasValue | |
{ | |
get {return Value != null;} | |
private set {} | |
} | |
public T Get | |
{ | |
get | |
{ | |
if(Value == null) | |
throw new InvalidOperationException("Value cannot be null when retrieving"); | |
return Value; | |
} | |
private set {} | |
} | |
public Option(T value) | |
{ | |
Value = value; | |
} | |
public T GetOrElse(T other) | |
{ | |
if(Value == null) return other; | |
return Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment