Skip to content

Instantly share code, notes, and snippets.

@riezebosch
Last active October 4, 2019 07:11
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 riezebosch/fc3b59387e834a538394327cb369773e to your computer and use it in GitHub Desktop.
Save riezebosch/fc3b59387e834a538394327cb369773e to your computer and use it in GitHub Desktop.
exploring C# 8
public static IArgumentMatcher? Create(Expression arg) => arg switch
{
MethodCallExpression call when call.Method.DeclaringType == typeof(Arg) => call.Method.Name switch
{
nameof(Arg.Ignore) => (IArgumentMatcher)new IgnoreArgument(),
nameof(Arg.Where) => new LambdaArgument(call.Arguments.Single()),
_ => throw new InvalidOperationException()
},
_ => null
};
public static IArgumentMatcher Create(Expression arg)
{
if (arg is MethodCallExpression call && call.Method.DeclaringType == typeof(Arg))
{
switch (call.Method.Name)
{
case "Ignore":
return new IgnoreArgument();
case "Equals":
return new EqualsArgument(call.Arguments[0]);
default:
throw new NotImplementedException();
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment