Skip to content

Instantly share code, notes, and snippets.

@khellang
Last active October 1, 2015 17:26
Show Gist options
  • Save khellang/de6ccc7f5ad658730551 to your computer and use it in GitHub Desktop.
Save khellang/de6ccc7f5ad658730551 to your computer and use it in GitHub Desktop.
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 :(
}
}
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