• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Giorgi / DuckDB.NET / 22194655451

19 Feb 2026 06:26PM UTC coverage: 89.638% (+0.3%) from 89.325%
22194655451

push

github

Giorgi
Add SuppressGCTransition to duckdb_scalar_function_set_error

1225 of 1421 branches covered (86.21%)

Branch coverage included in aggregate %.

2469 of 2700 relevant lines covered (91.44%)

527186.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.77
/DuckDB.NET.Data/Extensions/TypeExtensions.cs
1
using System.Diagnostics.CodeAnalysis;
2

3
namespace DuckDB.NET.Data.Extensions;
4

5
internal static class TypeExtensions
6
{
7
    private static readonly HashSet<Type> FloatingNumericTypes = [typeof(decimal), typeof(float), typeof(double)];
3✔
8

9
    private static readonly HashSet<Type> IntegralNumericTypes =
3✔
10
    [
3✔
11
        typeof(byte), typeof(sbyte),
3✔
12
        typeof(short), typeof(ushort),
3✔
13
        typeof(int), typeof(uint),
3✔
14
        typeof(long), typeof(ulong),
3✔
15
        typeof(BigInteger)
3✔
16
    ];
3✔
17

18
    private static readonly Dictionary<Type, DuckDBType> ClrToDuckDBTypeMap = new()
3✔
19
    {
3✔
20
        { typeof(bool), DuckDBType.Boolean },
3✔
21
        { typeof(sbyte), DuckDBType.TinyInt },
3✔
22
        { typeof(short), DuckDBType.SmallInt },
3✔
23
        { typeof(int), DuckDBType.Integer },
3✔
24
        { typeof(long), DuckDBType.BigInt },
3✔
25
        { typeof(byte), DuckDBType.UnsignedTinyInt },
3✔
26
        { typeof(ushort), DuckDBType.UnsignedSmallInt },
3✔
27
        { typeof(uint), DuckDBType.UnsignedInteger },
3✔
28
        { typeof(ulong), DuckDBType.UnsignedBigInt },
3✔
29
        { typeof(float), DuckDBType.Float },
3✔
30
        { typeof(double), DuckDBType.Double},
3✔
31
        { typeof(Guid), DuckDBType.Uuid},
3✔
32
        { typeof(DateTime), DuckDBType.Timestamp},
3✔
33
        { typeof(TimeSpan), DuckDBType.Interval},
3✔
34
        { typeof(DateOnly), DuckDBType.Date},
3✔
35
        { typeof(TimeOnly), DuckDBType.Time},
3✔
36
        { typeof(DateTimeOffset), DuckDBType.TimestampTz},
3✔
37
        { typeof(BigInteger), DuckDBType.HugeInt},
3✔
38
        { typeof(string), DuckDBType.Varchar},
3✔
39
        { typeof(decimal), DuckDBType.Decimal},
3✔
40
        { typeof(object), DuckDBType.Any},
3✔
41
    };
3✔
42

43
    public static bool IsNull([NotNullWhen(false)] this object? value) => value is null or DBNull;
12,735✔
44

45
    public static Type UnderlyingTypeOrSelf(this Type type) => Nullable.GetUnderlyingType(type) ?? type;
612✔
46

47
    public static (bool isNullableValueType, Type type) IsNullableValueType<T>()
48
    {
49
        var targetType = typeof(T);
5,654,049✔
50

51
        var isNullableValueType = default(T) is null && targetType.IsValueType;
5,654,049✔
52

53
        return (isNullableValueType, targetType);
5,654,049✔
54
    }
55

56
    public static bool IsFloatingNumericType<T>()
57
    {
58
        return FloatingNumericTypes.Contains(typeof(T));
2,806,355✔
59
    }
60

61
    public static bool IsIntegralNumericType<T>()
62
    {
63
        return IntegralNumericTypes.Contains(typeof(T));
2,806,355✔
64
    }
65

66
    public static bool IsNumeric(this Type type)
67
    {
68
        return IntegralNumericTypes.Contains(type) || FloatingNumericTypes.Contains(type);
10,634,487✔
69
    }
70

71
    public static bool AllowsNullValue(this Type type, out bool isNullableValueType, out Type? underlyingType)
72
    {
73
        underlyingType = Nullable.GetUnderlyingType(type);
1,042,242✔
74
        isNullableValueType = underlyingType != null;
1,042,242✔
75

76
        var isNullable = isNullableValueType || !type.IsValueType;
1,042,242✔
77

78
        return isNullable;
307,706✔
79
    }
80

81
    public static DuckDBLogicalType GetLogicalType<T>() => GetLogicalType(typeof(T));
102✔
82

83
    public static DuckDBLogicalType GetLogicalType(this Type type)
84
    {
85
        type = type.UnderlyingTypeOrSelf();
585✔
86

87
        if (type == typeof(decimal))
585✔
88
        {
89
            return NativeMethods.LogicalType.DuckDBCreateDecimalType(38, 18);
15✔
90
        }
91

92
        if (ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType))
570!
93
        {
94
            return NativeMethods.LogicalType.DuckDBCreateLogicalType(duckDBType);
570✔
95
        }
96

97
        throw new InvalidOperationException($"Cannot map type {type.FullName} to DuckDBType.");
×
98
    }
99

100
    public static DuckDBType GetDuckDBType(this Type type) => ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType) ? duckDBType : DuckDBType.Invalid;
27!
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc