-
-
Save rarous/7872728 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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(); | |
} | |
} |
This file contains hidden or 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 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