From 0987f3936e237dfc1bffee7fe7bc426cc33f8527 Mon Sep 17 00:00:00 2001 From: Quin Lynch Date: Wed, 5 Jul 2023 09:56:43 -0300 Subject: [PATCH] init --- .../Binary/Builders/Info/EdgeDBTypeConstructorInfo.cs | 5 +---- src/EdgeDB.Net.Driver/Binary/Builders/TypeBuilder.cs | 1 + src/EdgeDB.Net.Driver/Extensions/TypeExtensions.cs | 5 +++++ src/EdgeDB.Net.Driver/Utils/TypeArgumentUtils.cs | 6 +----- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/EdgeDB.Net.Driver/Binary/Builders/Info/EdgeDBTypeConstructorInfo.cs b/src/EdgeDB.Net.Driver/Binary/Builders/Info/EdgeDBTypeConstructorInfo.cs index 6d1d08ef..83674354 100644 --- a/src/EdgeDB.Net.Driver/Binary/Builders/Info/EdgeDBTypeConstructorInfo.cs +++ b/src/EdgeDB.Net.Driver/Binary/Builders/Info/EdgeDBTypeConstructorInfo.cs @@ -47,11 +47,8 @@ public static bool TryGetConstructorInfo(Type type, EdgeDBPropertyMapInfo map, o if (!ctorParams.Any()) emptyCtor = ctor; - if (ctorParams.Length == 1) + if (ctorParams.Length == 1 && ctor.GetCustomAttribute() is not null) { - if (ctor.GetCustomAttribute() is null) - continue; - var param = ctorParams[0]; UpgradeInfo(ref info, new EdgeDBTypeConstructorInfo diff --git a/src/EdgeDB.Net.Driver/Binary/Builders/TypeBuilder.cs b/src/EdgeDB.Net.Driver/Binary/Builders/TypeBuilder.cs index 0c5ec95b..b788a892 100644 --- a/src/EdgeDB.Net.Driver/Binary/Builders/TypeBuilder.cs +++ b/src/EdgeDB.Net.Driver/Binary/Builders/TypeBuilder.cs @@ -197,6 +197,7 @@ internal static bool IsValidObjectType(Type type) type.IsAssignableTo(typeof(ITuple)) || type.IsAbstract || type.IsRecord() || + type.IsAnonymousType() || (type.IsClass || type.IsValueType) && EdgeDBTypeConstructorInfo.TryGetConstructorInfo(type, out _); } diff --git a/src/EdgeDB.Net.Driver/Extensions/TypeExtensions.cs b/src/EdgeDB.Net.Driver/Extensions/TypeExtensions.cs index ffae380c..4b81d3d0 100644 --- a/src/EdgeDB.Net.Driver/Extensions/TypeExtensions.cs +++ b/src/EdgeDB.Net.Driver/Extensions/TypeExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; @@ -8,6 +9,10 @@ namespace EdgeDB { internal static class TypeExtensions { + public static bool IsAnonymousType(this Type type) + => type.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Length > 0 && + type.FullName!.Contains("AnonymousType"); + public static bool IsRecord(this Type type) => type.GetMethods().Any(m => m.Name == "$"); diff --git a/src/EdgeDB.Net.Driver/Utils/TypeArgumentUtils.cs b/src/EdgeDB.Net.Driver/Utils/TypeArgumentUtils.cs index 4e81727d..f2891635 100644 --- a/src/EdgeDB.Net.Driver/Utils/TypeArgumentUtils.cs +++ b/src/EdgeDB.Net.Driver/Utils/TypeArgumentUtils.cs @@ -83,11 +83,7 @@ public TypeArgumentBuilder() private static readonly ConcurrentDictionary _builders = new(); public static bool IsValidArgumentType(Type type) - => _builders.ContainsKey(type) || - ( - type.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Length > 0 && - type.FullName!.Contains("AnonymousType") - ); + => _builders.ContainsKey(type) || type.IsAnonymousType(); [return: NotNullIfNotNull(nameof(value))] public static IDictionary? CreateArguments(Type type, object? value)