Skip to content

Commit

Permalink
Added support for value task to the field name tools
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Feb 23, 2020
1 parent 190b045 commit 46ba880
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Core/Abstractions/AttributeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static string NormalizeMethodName(MethodInfo method)
name = name.Substring(_get.Length);
}

if (typeof(Task).IsAssignableFrom(method.ReturnType)
if (IsAsyncMethod(method.ReturnType)
&& name.Length > _async.Length
&& name.EndsWith(_async, StringComparison.Ordinal))
{
Expand All @@ -96,6 +96,24 @@ private static string NormalizeMethodName(MethodInfo method)
return NormalizeName(name);
}

private static bool IsAsyncMethod(Type returnType)
{
if (typeof(Task).IsAssignableFrom(returnType)
|| typeof(ValueTask).IsAssignableFrom(returnType))
{
return true;
}

if (returnType.IsGenericType)
{
Type typeDefinition = returnType.GetGenericTypeDefinition();
return typeof(ValueTask<>) == typeDefinition
|| typeof(IAsyncEnumerable<>) == typeDefinition;
}

return false;
}

public static string GetGraphQLDescription(
this ICustomAttributeProvider attributeProvider)
{
Expand Down

0 comments on commit 46ba880

Please sign in to comment.