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

Giorgi / DuckDB.NET / 23004948356

12 Mar 2026 01:42PM UTC coverage: 89.595% (+0.07%) from 89.526%
23004948356

push

github

Giorgi
Update GitVersion

1277 of 1485 branches covered (85.99%)

Branch coverage included in aggregate %.

2658 of 2907 relevant lines covered (91.43%)

451450.8 hits per line

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

96.67
/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,176✔
46

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

50
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
51
    public static bool IsFloatingNumericType<T>()
52
    {
53
        return typeof(T) == typeof(decimal) || typeof(T) == typeof(float) || typeof(T) == typeof(double);
4,043,273✔
54
    }
55

56
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
57
    public static bool IsIntegralNumericType<T>()
58
    {
59
        return typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) ||
4,043,273✔
60
               typeof(T) == typeof(short) || typeof(T) == typeof(ushort) ||
4,043,273✔
61
               typeof(T) == typeof(int) || typeof(T) == typeof(uint) ||
4,043,273✔
62
               typeof(T) == typeof(long) || typeof(T) == typeof(ulong) ||
4,043,273✔
63
               typeof(T) == typeof(BigInteger);
4,043,273✔
64
    }
65

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

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

76
        var isNullable = isNullableValueType || !type.IsValueType;
1,041,827✔
77

78
        return isNullable;
307,015✔
79
    }
80

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

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

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

92
        if (ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType))
879!
93
        {
94
            return NativeMethods.LogicalType.DuckDBCreateLogicalType(duckDBType);
879✔
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