Skip to content

Instantly share code, notes, and snippets.

@rarous
Last active December 30, 2015 19:09
Show Gist options
  • Save rarous/7872728 to your computer and use it in GitHub Desktop.
Save rarous/7872728 to your computer and use it in GitHub Desktop.
public interface ChangePasswordResult
{ }
public class PasswordChanged : ChangePasswordResult
{ }
public class ChangeNotAuthorized : ChangePasswordResult
{ }
public static class ChangePasswordResultEx
{
public static TResult Match<TResult>(this ChangePasswordResult result, Func<TResult> success, Func<TResult> notAuthorized)
{
if (result is PasswordChanged)
return success();
return notAuthorized();
}
}
public abstract class ChangePasswordResult
{
public static readonly ChangePasswordResult PasswordChanged = new PasswordChangedImpl();
public static readonly ChangePasswordResult ChangeNotAuthorized = new ChangeNotAuthorizedImpl();
public abstract TResult Match<TResult>(Func<TResult> success, Func<TResult> notAuthorized);
class PasswordChangedImpl : ChangePasswordResult
{
public override TResult Match<TResult>(Func<TResult> success, Func<TResult> notAuthorized)
{
return success();
}
}
class ChangeNotAuthorizedImpl : ChangePasswordResult
{
public override TResult Match<TResult>(Func<TResult> success, Func<TResult> notAuthorized)
{
return notAuthorized();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment