Skip to content

Commit

Permalink
v8.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Abraham committed Dec 20, 2023
1 parent 692ada6 commit 61f7eb4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/TypeCache.GraphQL/TypeCache.GraphQL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<RootNamespace>TypeCache.GraphQL</RootNamespace>
<PackageId>TypeCache.GraphQL</PackageId>
<Version>8.0.0</Version>
<Version>8.0.1</Version>
<Authors>Samuel Abraham &lt;sam987883@gmail.com&gt;</Authors>
<Company>Samuel Abraham &lt;sam987883@gmail.com&gt;</Company>
<Title>TypeCache GraphQL</Title>
Expand Down Expand Up @@ -35,8 +35,8 @@ Automatic generation of SQL related endpoints.
</ItemGroup>

<ItemGroup>
<PackageReference Include="GraphQL" Version="7.6.1" />
<PackageReference Include="GraphQL.DataLoader" Version="7.6.1" />
<PackageReference Include="GraphQL" Version="7.7.2" />
<PackageReference Include="GraphQL.DataLoader" Version="7.7.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/TypeCache.GraphQL/Types/GraphQLScalarType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public GraphQLScalarType(string typeName, Func<T, bool> canParseLiteral, Func<T,
null => _GraphQLNullValue,
true => _GraphQLTrueBooleanValue,
false => _GraphQLFalseBooleanValue,
Enum x => new GraphQLEnumValue(new GraphQLName(x.ToString("F"))),
sbyte x => new GraphQLIntValue(x),
short x => new GraphQLIntValue(x),
int x => new GraphQLIntValue(x),
Expand All @@ -75,7 +76,6 @@ public GraphQLScalarType(string typeName, Func<T, bool> canParseLiteral, Func<T,
DateTimeOffset x => new GraphQLStringValue(x.ToISO8601()),
TimeOnly x => new GraphQLStringValue(x.ToISO8601()),
TimeSpan x => new GraphQLStringValue(x.ToText()),
Enum x => new GraphQLEnumValue(new GraphQLName(x.ToString("F"))),
char x => new GraphQLStringValue(x.ToString()),
string x => new GraphQLStringValue(x),
_ => ThrowASTConversionError(value)
Expand Down
1 change: 1 addition & 0 deletions src/TypeCache/Extensions/ReflectionExtensions.Handles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static MethodBase ToMethodBase(this RuntimeMethodHandle @this)
[MethodImpl(AggressiveInlining), DebuggerHidden]
public static MethodBase ToMethodBase(this RuntimeMethodHandle @this, RuntimeTypeHandle typeHandle)
=> MethodBase.GetMethodFromHandle(@this, typeHandle) ?? throw new UnreachableException("MethodBase.GetMethodFromHandle(..., ...) returned null.");

/// <inheritdoc cref="Type.GetTypeFromHandle(RuntimeTypeHandle)"/>
/// <remarks>
/// <c>=&gt; <see cref="Type"/>.GetTypeFromHandle(@<paramref name="this"/>) ?? throw new UnreachableException("Type.GetTypeFromHandle(...) returned null.");</c>
Expand Down
2 changes: 1 addition & 1 deletion src/TypeCache/TypeCache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RootNamespace>TypeCache</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageId>TypeCache</PackageId>
<Version>8.0.0</Version>
<Version>8.0.1</Version>
<Authors>Samuel Abraham &lt;sam987883@gmail.com&gt;</Authors>
<Company>Samuel Abraham &lt;sam987883@gmail.com&gt;</Company>
<Title>TypeCache Reflection</Title>
Expand Down
51 changes: 14 additions & 37 deletions src/TypeCache/Utilities/TypeStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ internal static class TypeStore
(typeof(ICollection<>).TypeHandle, CollectionType.Collection)
}.ToFrozenSet();

public static IReadOnlyList<(RuntimeTypeHandle Handle, ObjectType ObjectType)> ObjectTypeMap =>
[
public static IReadOnlySet<(RuntimeTypeHandle Handle, ObjectType ObjectType)> ObjectTypeMap => new[]
{
(typeof(Attribute).TypeHandle, ObjectType.Attribute),
(typeof(DataColumn).TypeHandle, ObjectType.DataColumn),
(typeof(DataRow).TypeHandle, ObjectType.DataRow),
Expand Down Expand Up @@ -126,25 +126,16 @@ internal static class TypeStore
(typeof(ValueTuple<,,,,,>).TypeHandle, ObjectType.ValueTuple),
(typeof(ValueTuple<,,,,,,>).TypeHandle, ObjectType.ValueTuple),
(typeof(ValueTuple<,,,,,,,>).TypeHandle, ObjectType.ValueTuple)
];
}.ToFrozenSet();

static TypeStore()
{
CollectionTypes = new LazyDictionary<RuntimeTypeHandle, CollectionType>(handle =>
{
var type = handle.ToType();

if (type.IsArray)
return CollectionType.Array;

foreach (var map in CollectionTypeMap)
handle.ToType() switch
{
if (type.Implements(map.Handle.ToType()))
return map.CollectionType;
}

return CollectionType.None;
});
{ IsArray: true } => CollectionType.Array,
Type type => CollectionTypeMap.FirstOrDefault(_ => type.Implements(_.Handle.ToType())).CollectionType
});
DefaultValueFactory = new LazyDictionary<RuntimeTypeHandle, Func<object?>>(handle =>
handle.ToType().ToDefaultExpression().As<object>().Lambda<Func<object?>>().Compile());
DefaultValueTypeConstructorInvokes = new LazyDictionary<RuntimeTypeHandle, Func<object>>(handle =>
Expand All @@ -159,28 +150,14 @@ static TypeStore()
_ => throw new UnreachableException("Method or Constructor not found.")
});
ObjectTypes = new LazyDictionary<RuntimeTypeHandle, ObjectType>(handle =>
{
var type = handle.ToType();

if (type.IsPointer)
return ObjectType.Pointer;

if (type == typeof(object))
return ObjectType.Object;

if (type.IsPrimitive || type.GetScalarType() is not ScalarType.None)
return ObjectType.DataType;

var count = ObjectTypeMap.Count;
for (var i = 0; i < count; ++i)
handle.ToType() switch
{
var map = ObjectTypeMap[i];
if (type.Implements(map.Handle.ToType()))
return map.ObjectType;
}

return ObjectType.Unknown;
});
{ IsPointer: true } => ObjectType.Pointer,
{ IsPrimitive: true } => ObjectType.DataType,
Type type when type == typeof(object) => ObjectType.Object,
Type type when type.GetScalarType() is not ScalarType.None => ObjectType.DataType,
Type type => ObjectTypeMap.FirstOrDefault(_ => type.Implements(_.Handle.ToType())).ObjectType
});
DataTypes = new Dictionary<RuntimeTypeHandle, ScalarType>(30)
{
{ typeof(BigInteger).TypeHandle, ScalarType.BigInteger },
Expand Down

0 comments on commit 61f7eb4

Please sign in to comment.