Created
May 7, 2018 19:59
-
-
Save MNie/d8e8e1e5e3825766050c6f956eb35d53 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
private static QueryTest BuildQuery(string type, TArguments args, IEnumerable<string> fields) | |
{ | |
var arguments = args == null ? "" : GetArguments(args); | |
var query = $"{{{type}{arguments}{{{string.Join(' ', fields)}}}}}"; | |
return new QueryTest(query); | |
} | |
private static string GetArguments(TArguments args) | |
{ | |
var values = args.GetType() | |
.GetFields() | |
.Select(x => new { name = x.Name, value = x.GetValue(args) }) | |
.Where(x => x.value != null) | |
.Select(x => $"{x.name}:{FormatArgument(x.value)}"); | |
return $"({string.Join(',', values)})"; | |
} | |
private static string FormatArgument(object value) => | |
value is string | |
? $"\"{value}\"" | |
: $"{value}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment