Skip to content

Commit 2c1cba7

Browse files
committed
Drop .Net Standard support
1 parent 31be677 commit 2c1cba7

34 files changed

+45
-350
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<PropertyGroup Label="Common assembly attributes">
12-
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
12+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
1313
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
1414
<LangVersion>default</LangVersion>
1515

DuckDB.NET.Bindings/DuckDBDateOnly.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,10 @@ public readonly struct DuckDBDateOnly(int year, byte month, byte day)
5353

5454
public DateTime ToDateTime() => new DateTime(Year, Month, Day);
5555

56-
#if NET6_0_OR_GREATER
57-
5856
public static DuckDBDateOnly FromDateOnly(DateOnly dateOnly) => new DuckDBDateOnly(dateOnly.Year, (byte)dateOnly.Month, (byte)dateOnly.Day);
5957

6058
public DateOnly ToDateOnly() => new DateOnly(Year, Month, Day);
6159

62-
#endif
63-
6460
/// <summary>
6561
/// Converts a DuckDBDate to DuckDBDateOnly, handling infinity values.
6662
/// </summary>
@@ -91,11 +87,7 @@ public DuckDBDate ToDuckDBDate()
9187

9288
public static explicit operator DuckDBDateOnly(DateTime dateTime) => FromDateTime(dateTime);
9389

94-
#if NET6_0_OR_GREATER
95-
9690
public static implicit operator DateOnly(DuckDBDateOnly dateOnly) => dateOnly.ToDateOnly();
9791

9892
public static implicit operator DuckDBDateOnly(DateOnly date) => DuckDBDateOnly.FromDateOnly(date);
99-
100-
#endif
10193
}

DuckDB.NET.Bindings/DuckDBInterval.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ public static explicit operator TimeSpan(DuckDBInterval interval)
2020
}
2121
public static implicit operator DuckDBInterval(TimeSpan timeSpan) => FromTimeSpan(timeSpan);
2222

23-
#if NET6_0_OR_GREATER
2423
public bool TryConvert([NotNullWhen(true)] out TimeSpan? timeSpan)
25-
#else
26-
public bool TryConvert(out TimeSpan? timeSpan)
27-
#endif
2824
{
2925
(timeSpan, var exception) = ToTimeSpan(this);
3026
return exception is null;

DuckDB.NET.Bindings/DuckDBTimeOnly.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ internal static DuckDBTimeOnly FromDateTime(DateTime dateTime)
3838
public static explicit operator DateTime(DuckDBTimeOnly timeOnly) => timeOnly.ToDateTime();
3939
public static explicit operator DuckDBTimeOnly(DateTime dateTime) => FromDateTime(dateTime);
4040

41-
#if NET6_0_OR_GREATER
4241
internal static DuckDBTimeOnly FromTimeOnly(TimeOnly timeOnly)
4342
{
4443
var microsecond = timeOnly.GetMicrosecond();
@@ -48,6 +47,4 @@ internal static DuckDBTimeOnly FromTimeOnly(TimeOnly timeOnly)
4847
public static implicit operator TimeOnly(DuckDBTimeOnly time) => new(time.Ticks);
4948

5049
public static implicit operator DuckDBTimeOnly(TimeOnly time) => FromTimeOnly(time);
51-
52-
#endif
5350
}

DuckDB.NET.Bindings/DuckDBWrapperObjects.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,9 @@ public T GetValue<T>()
150150

151151
DuckDBType.Varchar => Cast(NativeMethods.Value.DuckDBGetVarchar(this)),
152152

153-
#if NET6_0_OR_GREATER
154153
DuckDBType.Date => Cast((DateOnly)DuckDBDateOnly.FromDuckDBDate(NativeMethods.Value.DuckDBGetDate(this))),
155154
DuckDBType.Time => Cast((TimeOnly)NativeMethods.DateTimeHelpers.DuckDBFromTime(NativeMethods.Value.DuckDBGetTime(this))),
156-
#else
157-
DuckDBType.Date => Cast(DuckDBDateOnly.FromDuckDBDate(NativeMethods.Value.DuckDBGetDate(this)).ToDateTime()),
158-
DuckDBType.Time => Cast(NativeMethods.DateTimeHelpers.DuckDBFromTime(NativeMethods.Value.DuckDBGetTime(this)).ToDateTime()),
159-
#endif
155+
160156
//DuckDBType.TimeTz => expr,
161157
DuckDBType.Interval => Cast((TimeSpan)NativeMethods.Value.DuckDBGetInterval(this)),
162158
DuckDBType.Timestamp => Cast(DuckDBTimestamp.FromDuckDBTimestampStruct(NativeMethods.Value.DuckDBGetTimestamp(this)).ToDateTime()),

DuckDB.NET.Bindings/Extensions/DateTimeExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Text;
32

43
namespace DuckDB.NET.Native.Extensions;
54

@@ -17,11 +16,9 @@ internal static int GetMicrosecond(this TimeSpan timeSpan)
1716
return (int)(ticks / 10);
1817
}
1918

20-
#if NET6_0_OR_GREATER
2119
internal static int GetMicrosecond(this TimeOnly timeOnly)
2220
{
2321
var ticks = timeOnly.Ticks - GetTicks(timeOnly.Hour, timeOnly.Minute, timeOnly.Second);
2422
return (int)(ticks / 10);
2523
}
26-
#endif
2724
}

DuckDB.NET.Bindings/Extensions/PointerExtensions.cs

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,18 @@ namespace DuckDB.NET.Native;
88
public static class PointerExtensions
99
{
1010
[EditorBrowsable(EditorBrowsableState.Never)]
11-
public static string ToManagedString(this IntPtr unmanagedString, bool freeWhenCopied = true, int? length = null)
11+
public static unsafe string ToManagedString(this IntPtr unmanagedString, bool freeWhenCopied = true, int? length = null)
1212
{
13-
string result;
14-
#if NET6_0_OR_GREATER
15-
result = length.HasValue
16-
? Marshal.PtrToStringUTF8(unmanagedString, length.Value)
17-
: Marshal.PtrToStringUTF8(unmanagedString) ?? string.Empty;
18-
#else
1913
if (unmanagedString == IntPtr.Zero)
20-
{
21-
return "";
22-
}
23-
24-
if (length == null)
25-
{
26-
length = 0;
27-
28-
while (Marshal.ReadByte(unmanagedString, length.Value) != 0)
29-
{
30-
length++;
31-
}
32-
}
33-
34-
if (length == 0)
3514
{
3615
return string.Empty;
3716
}
3817

39-
var byteArray = new byte[length.Value];
18+
var span = length.HasValue ? new ReadOnlySpan<byte>((byte*)unmanagedString, length.Value)
19+
: MemoryMarshal.CreateReadOnlySpanFromNullTerminated((byte*)unmanagedString);
4020

41-
Marshal.Copy(unmanagedString, byteArray, 0, length.Value);
21+
var result = Encoding.UTF8.GetString(span);
4222

43-
result = Encoding.UTF8.GetString(byteArray, 0, length.Value);
44-
#endif
4523
if (freeWhenCopied)
4624
{
4725
NativeMethods.Helpers.DuckDBFree(unmanagedString);
@@ -51,27 +29,5 @@ public static string ToManagedString(this IntPtr unmanagedString, bool freeWhenC
5129
}
5230

5331
[EditorBrowsable(EditorBrowsableState.Never)]
54-
public static SafeUnmanagedMemoryHandle ToUnmanagedString(this string? managedString)
55-
{
56-
#if NET6_0_OR_GREATER
57-
var pointer = Marshal.StringToCoTaskMemUTF8(managedString);
58-
return new SafeUnmanagedMemoryHandle(pointer);
59-
#else
60-
61-
if (managedString == null)
62-
{
63-
return new SafeUnmanagedMemoryHandle();
64-
}
65-
66-
int len = Encoding.UTF8.GetByteCount(managedString);
67-
68-
var buffer = new byte[len + 1];
69-
Encoding.UTF8.GetBytes(managedString, 0, managedString.Length, buffer, 0);
70-
71-
var nativeUtf8 = Marshal.AllocCoTaskMem(buffer.Length);
72-
Marshal.Copy(buffer, 0, nativeUtf8, buffer.Length);
73-
74-
return new SafeUnmanagedMemoryHandle(nativeUtf8);
75-
#endif
76-
}
32+
public static SafeUnmanagedMemoryHandle ToUnmanagedString(this string? managedString) => new(Marshal.StringToCoTaskMemUTF8(managedString));
7733
}

DuckDB.NET.Bindings/NativeMethods/NativeMethods.Value.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static class Value
163163

164164
public static DuckDBValue DuckDBCreateListValue(DuckDBLogicalType logicalType, DuckDBValue[] values, int count)
165165
{
166-
var duckDBValue = DuckDBCreateListValue(logicalType, values.Select(item => item.DangerousGetHandle()).ToArray(), count);
166+
var duckDBValue = DuckDBCreateListValue(logicalType, [..values.Select(item => item.DangerousGetHandle())], count);
167167

168168
duckDBValue.SetChildValues(values);
169169

@@ -172,7 +172,7 @@ public static DuckDBValue DuckDBCreateListValue(DuckDBLogicalType logicalType, D
172172

173173
public static DuckDBValue DuckDBCreateArrayValue(DuckDBLogicalType logicalType, DuckDBValue[] values, int count)
174174
{
175-
var duckDBValue = DuckDBCreateArrayValue(logicalType, values.Select(item => item.DangerousGetHandle()).ToArray(), count);
175+
var duckDBValue = DuckDBCreateArrayValue(logicalType, [..values.Select(item => item.DangerousGetHandle())], count);
176176

177177
duckDBValue.SetChildValues(values);
178178

DuckDB.NET.Data/Common/IsExternalInit.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

DuckDB.NET.Data/DataChunk/Reader/DateTimeVectorDataReader.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ internal sealed class DateTimeVectorDataReader : VectorDataReaderBase
1212
private static readonly Type DateTimeOffsetType = typeof(DateTimeOffset);
1313
private static readonly Type DateTimeOffsetNullableType = typeof(DateTimeOffset?);
1414

15-
#if NET6_0_OR_GREATER
1615
private static readonly Type DateOnlyType = typeof(DateOnly);
1716
private static readonly Type DateOnlyNullableType = typeof(DateOnly?);
1817

1918
private static readonly Type TimeOnlyType = typeof(TimeOnly);
2019
private static readonly Type TimeOnlyNullableType = typeof(TimeOnly?);
21-
#endif
2220

2321
internal unsafe DateTimeVectorDataReader(void* dataPointer, ulong* validityMaskPointer, DuckDBType columnType, string columnName) : base(dataPointer, validityMaskPointer, columnType, columnName)
2422
{
@@ -37,12 +35,10 @@ protected override T GetValidValue<T>(ulong offset, Type targetType)
3735
ThrowInfinityDateException();
3836
}
3937

40-
#if NET6_0_OR_GREATER
4138
if (targetType == DateOnlyType || targetType == DateOnlyNullableType)
4239
{
4340
ThrowInfinityDateException();
4441
}
45-
#endif
4642
return (T)(object)dateOnly;
4743
}
4844

@@ -52,13 +48,11 @@ protected override T GetValidValue<T>(ulong offset, Type targetType)
5248
return (T)(object)dateTime;
5349
}
5450

55-
#if NET6_0_OR_GREATER
5651
if (targetType == DateOnlyType || targetType == DateOnlyNullableType)
5752
{
5853
var dateTime = (DateOnly)dateOnly;
5954
return (T)(object)dateTime;
6055
}
61-
#endif
6256
return (T)(object)dateOnly;
6357
}
6458

@@ -72,13 +66,11 @@ protected override T GetValidValue<T>(ulong offset, Type targetType)
7266
return (T)(object)dateTime;
7367
}
7468

75-
#if NET6_0_OR_GREATER
7669
if (targetType == TimeOnlyType || targetType == TimeOnlyNullableType)
7770
{
7871
var dateTime = (TimeOnly)timeOnly;
7972
return (T)(object)dateTime;
8073
}
81-
#endif
8274
return (T)(object)timeOnly;
8375
}
8476

@@ -186,12 +178,10 @@ private object GetDate(ulong offset, Type targetType)
186178
ThrowInfinityDateException();
187179
}
188180

189-
#if NET6_0_OR_GREATER
190181
if (targetType == DateOnlyType)
191182
{
192183
ThrowInfinityDateException();
193184
}
194-
#endif
195185

196186
return dateOnly;
197187
}
@@ -201,12 +191,10 @@ private object GetDate(ulong offset, Type targetType)
201191
return (DateTime)dateOnly;
202192
}
203193

204-
#if NET6_0_OR_GREATER
205194
if (targetType == DateOnlyType)
206195
{
207196
return (DateOnly)dateOnly;
208197
}
209-
#endif
210198

211199
return dateOnly;
212200
}
@@ -219,12 +207,10 @@ private object GetTime(ulong offset, Type targetType)
219207
return (DateTime)timeOnly;
220208
}
221209

222-
#if NET6_0_OR_GREATER
223210
if (targetType == TimeOnlyType)
224211
{
225212
return (TimeOnly)timeOnly;
226213
}
227-
#endif
228214

229215
return timeOnly;
230216
}

0 commit comments

Comments
 (0)