Last active
August 29, 2015 14:05
-
-
Save Porges/3194c7f4655326579852 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 struct Result<T>(T value) | |
{ | |
public static implicit operator Result<T>(T value) => new Result<T>(value); | |
public static implicit operator Result<T>(Result<Any> any) => default(Result<T>); | |
public static implicit operator Result<T>(Result<T, Any> value) => new Result<T>(value.Value); | |
public bool HasValue { get; } = true; | |
public T Value { get; } = 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
// Note that this doesn't even have readonly fields, which | |
// would be another 2 lines + uglier properties | |
public struct ResultOld<T> | |
{ | |
public ResultOld(T value) : this() | |
{ | |
HasValue = true; | |
Value = value; | |
} | |
public static implicit operator ResultOld<T>(T value) | |
{ | |
return new ResultOld<T>(value); | |
} | |
public static implicit operator ResultOld<T>(Result<Any> any) | |
{ | |
return default(ResultOld<T>); | |
} | |
public static implicit operator ResultOld<T>(Result<T, Any> value) | |
{ | |
return new ResultOld<T>(value.Value); | |
} | |
public bool HasValue { get; private set; } | |
public T Value { get; private set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment