Created
March 22, 2020 02:50
-
-
Save drusellers/a890bef6484d61fdf932405f61b3b695 to your computer and use it in GitHub Desktop.
This file contains 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
// 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 }; | |
} | |
} |
This file contains 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 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