Last active
October 4, 2019 07:11
-
-
Save riezebosch/fc3b59387e834a538394327cb369773e to your computer and use it in GitHub Desktop.
exploring C# 8
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
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 | |
}; |
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
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