Last active
June 23, 2017 15:39
-
-
Save rflechner/fa0a05fceb328feeb49e199c2a76e2c6 to your computer and use it in GitHub Desktop.
C# railway oriented programming
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
var result = Service.DoSomeThing(); | |
switch (result) | |
{ | |
case Success<string> success: | |
_logger.Information("ok it works"); | |
break; | |
case Failure<string> failure: | |
_logger.Error(failure.Exception, "Error: it sucks"); | |
break; | |
} | |
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
namespace Finexkap.MicroServices.Salesforce.Models.Railway | |
{ | |
public abstract class Result<T> | |
{ | |
} | |
public class Success<T> : Result<T> | |
{ | |
public Success(T model) | |
{ | |
Model = model; | |
} | |
public T Model { get; } | |
} | |
public class Failure<T> : Result<T> | |
{ | |
public Failure(Exception exception) | |
{ | |
Exception = exception; | |
} | |
public Exception Exception { get; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment