Skip to content

Instantly share code, notes, and snippets.

@rflechner
Last active June 23, 2017 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rflechner/fa0a05fceb328feeb49e199c2a76e2c6 to your computer and use it in GitHub Desktop.
Save rflechner/fa0a05fceb328feeb49e199c2a76e2c6 to your computer and use it in GitHub Desktop.
C# railway oriented programming
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;
}
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