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

Giorgi / DuckDB.NET / 22729722447

05 Mar 2026 04:48PM UTC coverage: 89.491% (-0.2%) from 89.682%
22729722447

push

github

Giorgi
Use field keyword

1260 of 1467 branches covered (85.89%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 2 files covered. (100.0%)

12 existing lines in 3 files now uncovered.

2606 of 2853 relevant lines covered (91.34%)

451516.24 hits per line

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

95.45
/DuckDB.NET.Data/Extensions/TypeExtensions.cs
1
using System.Diagnostics.CodeAnalysis;
2
using System.Runtime.CompilerServices;
3

4
namespace DuckDB.NET.Data.Extensions;
5

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

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

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

44
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
45
    public static bool IsNull([NotNullWhen(false)] this object? value) => value is null or DBNull;
12,547✔
46

47
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
48
    public static Type UnderlyingTypeOrSelf(this Type type) => Nullable.GetUnderlyingType(type) ?? type;
828✔
49

50
    public static bool IsFloatingNumericType<T>()
51
    {
52
        return FloatingNumericTypes.Contains(typeof(T));
4,038,872✔
53
    }
54

55
    public static bool IsIntegralNumericType<T>()
56
    {
57
        return IntegralNumericTypes.Contains(typeof(T));
4,038,872✔
58
    }
59

60
    public static bool IsNumeric(this Type type)
61
    {
62
        return IntegralNumericTypes.Contains(type) || FloatingNumericTypes.Contains(type);
9,628,730✔
63
    }
64

65
    public static bool AllowsNullValue(this Type type, out bool isNullableValueType, out Type? underlyingType)
66
    {
67
        underlyingType = Nullable.GetUnderlyingType(type);
1,042,953✔
68
        isNullableValueType = underlyingType != null;
1,042,953✔
69

70
        var isNullable = isNullableValueType || !type.IsValueType;
1,042,953✔
71

72
        return isNullable;
308,315✔
73
    }
74

75
    public static DuckDBLogicalType GetLogicalType<T>() => typeof(T).GetLogicalType();
165✔
76

77
    public static DuckDBLogicalType GetLogicalType(this Type type)
78
    {
79
        type = type.UnderlyingTypeOrSelf();
801✔
80

81
        if (type == typeof(decimal))
801✔
82
        {
83
            return NativeMethods.LogicalType.DuckDBCreateDecimalType(38, 18);
15✔
84
        }
85

86
        if (ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType))
786!
87
        {
88
            return NativeMethods.LogicalType.DuckDBCreateLogicalType(duckDBType);
786✔
89
        }
90

UNCOV
91
        throw new InvalidOperationException($"Cannot map type {type.FullName} to DuckDBType.");
×
92
    }
93

94
    public static DuckDBType GetDuckDBType(this Type type) => ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType) ? duckDBType : DuckDBType.Invalid;
27!
95
}
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