Skip to content

Instantly share code, notes, and snippets.

@drusellers
Created March 22, 2020 02:50
Show Gist options
  • Save drusellers/a890bef6484d61fdf932405f61b3b695 to your computer and use it in GitHub Desktop.
Save drusellers/a890bef6484d61fdf932405f61b3b695 to your computer and use it in GitHub Desktop.
// could be struct?
public class MultiResponse<T, E> {
// could be struct?
public class OkResponse: MultiResponse<T,E> {
public T value;
}
public class ErrResponse: MultiResponse<T,E> {
public E value;
}
public static MultiResponse<T, E> Ok(T value) {
return new OkResponse { value = value };
}
public static MultiResponse<T,E> Err(E value) {
return new ErrResponse { value = value };
}
}
namespace MassTransit.Tests
{
using MassTransit;
[TestFixture]
public class MultiResponseTest
{
[Test]
public void CanMatch() {
var good = MultiResponse<string, int>.Ok("hi");
var bad = MultiResponse<string, int>.Err(1);
switch(good) {
case MultiResponse<string, int>.OkResponse r:
return;
case MultiResponse<string, int>.ErrResponse e:
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment