This repository has been archived by the owner on Jul 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify Include method so that it accepts QueryExtensions methods. Imp…
…lemented task 2 from issue #2
- Loading branch information
Showing
4 changed files
with
172 additions
and
111 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
|
||
namespace GraphQLinq | ||
{ | ||
static class ExtensionsUtils | ||
{ | ||
internal static bool IsPrimitiveOrString(this Type type) | ||
{ | ||
return type.IsPrimitive || type == typeof(string); | ||
} | ||
|
||
internal static bool IsList(this Type type) | ||
{ | ||
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>); | ||
} | ||
|
||
internal static bool HasNestedProperties(this Type type) | ||
{ | ||
var trueType = GetTypeOrListType(type); | ||
|
||
return !IsPrimitiveOrString(trueType); | ||
} | ||
|
||
internal static Type GetTypeOrListType(this Type type) | ||
{ | ||
if (type.IsList()) | ||
{ | ||
var genericArguments = type.GetGenericArguments(); | ||
|
||
return genericArguments[0].GetTypeOrListType(); | ||
} | ||
|
||
return type; | ||
} | ||
|
||
internal static Expression RemoveConvert(this Expression expression) | ||
{ | ||
while ((expression != null) | ||
&& (expression.NodeType == ExpressionType.Convert | ||
|| expression.NodeType == ExpressionType.ConvertChecked)) | ||
{ | ||
expression = RemoveConvert(((UnaryExpression)expression).Operand); | ||
} | ||
|
||
return expression; | ||
} | ||
|
||
internal static string ToCamelCase(this string input) | ||
{ | ||
if (char.IsLower(input[0])) | ||
{ | ||
return input; | ||
} | ||
return input.Substring(0, 1).ToLower() + input.Substring(1); | ||
} | ||
|
||
internal static string ToGraphQlType(this Type type) | ||
{ | ||
if (type == typeof(bool)) | ||
{ | ||
return "Boolean"; | ||
} | ||
|
||
if (type == typeof(int)) | ||
{ | ||
return "Int"; | ||
} | ||
|
||
if (type == typeof(string)) | ||
{ | ||
return "String!"; | ||
} | ||
|
||
if (type == typeof(float)) | ||
{ | ||
return "Float"; | ||
} | ||
|
||
if (type.IsList()) | ||
{ | ||
var listType = type.GetTypeOrListType(); | ||
return "[" + ToGraphQlType(listType) + "]"; | ||
} | ||
|
||
return type.Name; | ||
} | ||
} | ||
} |
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
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
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