Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Gonna love ChatGPT from time to time.
Best version of this method I wrote by hand was 7 lines. Now it's 3.
And it's perfectly readable.
private static DateOnly ParseDateArgument(GraphQLValue? argumentValue, IResolveFieldContext context)
{
return argumentValue switch
{
GraphQLStringValue strVal when DateOnly.TryParse(strVal.Value.ToString(), out var date) => date,
GraphQLVariable varVal when DateOnly.TryParse(context.Variables?.ValueFor(varVal.Name.StringValue)?.ToString(), out var date) => date,
_ => default
};
}
rant