Last active
October 1, 2015 17:26
-
-
Save khellang/de6ccc7f5ad658730551 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 ICommandHandler<in TCommand, out TResult> | |
{ | |
TResult Execute(TCommand command); | |
} | |
public interface ICommandHandler<in TCommand> : ICommandHandler<TCommand, Unit> { } | |
public struct Unit | |
{ | |
// This is really a hack around the lack of a proper Void type... | |
public static Unit Value { get; } = new Unit(); | |
} | |
public class CommandHandler : ICommandHandler<string> | |
{ | |
public Unit Execute(string command) | |
{ | |
return Unit.Value; // Have to return Unit here :( | |
} | |
} |
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 ICommandHandler<in TCommand, out TResult> | |
{ | |
TResult Execute(TCommand command); | |
} | |
public interface ICommandHandler<in TCommand> : ICommandHandler<TCommand, void> | |
{ | |
} | |
public class CommandHandler : ICommandHandler<string> | |
{ | |
public void Execute(string command) | |
{ | |
// No need to return anything! :D | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment