Skip to content

Instantly share code, notes, and snippets.

@UberMouse
Last active December 19, 2015 13:19
Show Gist options
  • Save UberMouse/5961667 to your computer and use it in GitHub Desktop.
Save UberMouse/5961667 to your computer and use it in GitHub Desktop.
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