X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ jobs:
pg_major: 16
config: Debug
test_tfm: net8.0
- os: ubuntu-22.04
pg_major: 16
config: Release
test_tfm: netcoreapp3.1
- os: macos-12
pg_major: 14
config: Release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<PropertyGroup>
<Authors>Shay Rojansky</Authors>
<!-- DbDataSource was introduced to .NET in net7.0. Before that Npgsql has its own built-in copy. -->
<TargetFrameworks Condition="'$(DeveloperBuild)' != 'True'">netstandard2.0;net7.0</TargetFrameworks>
<!-- This is why we have to build against both frameworks. -->
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition="'$(DeveloperBuild)' == 'True'">net8.0</TargetFrameworks>
<PackageTags>npgsql;postgresql;postgres;ado;ado.net;database;sql;di;dependency injection</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand All @@ -12,13 +13,10 @@
<ItemGroup>
<ProjectReference Include="..\Npgsql\Npgsql.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/Npgsql.DependencyInjection/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Runtime.CompilerServices;

#if NET5_0_OR_GREATER
[module: SkipLocalsInit]
#endif
19 changes: 3 additions & 16 deletions src/Npgsql.GeoJSON/Internal/GeoJSONConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,17 @@ public override ValueTask WriteAsync(PgWriter writer, T value, CancellationToken
if (crsType == GeoJSONOptions.None)
return null;

#if NETSTANDARD2_0
return cachedCrs.GetOrAdd(srid, srid =>
return cachedCrs.GetOrAdd(srid, static (srid, state) =>
{
var (crsMap, crsType) = state;
var authority = crsMap.GetAuthority(srid);

return authority is null
? throw new InvalidOperationException($"SRID {srid} unknown in spatial_ref_sys table")
: new NamedCRS(crsType == GeoJSONOptions.LongCRS
? "urn:ogc:def:crs:" + authority + "::" + srid
: authority + ":" + srid);
});
#else
return cachedCrs.GetOrAdd(srid, static (srid, state) =>
{
var (crsMap, crsType) = state;
var authority = crsMap.GetAuthority(srid);

return authority is null
? throw new InvalidOperationException($"SRID {srid} unknown in spatial_ref_sys table")
: new NamedCRS(crsType == GeoJSONOptions.LongCRS
? "urn:ogc:def:crs:" + authority + "::" + srid
: authority + ":" + srid);
}, (crsMap, crsType));
#endif
}, (crsMap, crsType));
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/Npgsql.GeoJSON/Npgsql.GeoJSON.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Authors>Yoh Deadfall;Shay Rojansky</Authors>
<Description>GeoJSON plugin for Npgsql, allowing mapping of PostGIS geometry types to GeoJSON types.</Description>
<PackageTags>npgsql;postgresql;postgres;postgis;geojson;spatial;ado;ado.net;database;sql</PackageTags>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition="'$(DeveloperBuild)' == 'True'">net8.0</TargetFramework>
</PropertyGroup>

Expand Down
2 changes: 0 additions & 2 deletions src/Npgsql.GeoJSON/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Runtime.CompilerServices;

#if NET5_0_OR_GREATER
[module: SkipLocalsInit]
#endif
4 changes: 2 additions & 2 deletions src/Npgsql.Json.NET/Npgsql.Json.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<Authors>Shay Rojansky</Authors>
<Description>Json.NET plugin for Npgsql, allowing transparent serialization/deserialization of JSON objects directly to and from the database.</Description>
<PackageTags>npgsql;postgresql;json;postgres;ado;ado.net;database;sql</PackageTags>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition="'$(DeveloperBuild)' == 'True'">net8.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition="'$(DeveloperBuild)' == 'True'">net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
2 changes: 0 additions & 2 deletions src/Npgsql.Json.NET/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Runtime.CompilerServices;

#if NET5_0_OR_GREATER
[module: SkipLocalsInit]
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
<Description>NetTopologySuite plugin for Npgsql, allowing mapping of PostGIS geometry types to NetTopologySuite types.</Description>
<PackageTags>npgsql;postgresql;postgres;postgis;spatial;nettopologysuite;nts;ado;ado.net;database;sql</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition="'$(DeveloperBuild)' == 'True'">net8.0</TargetFramework>
<NoWarn>$(NoWarn);NU5104</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NetTopologySuite.IO.PostGIS" />
<PackageReference Include="NetTopologySuite" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
</ItemGroup>

Expand Down
2 changes: 0 additions & 2 deletions src/Npgsql.NetTopologySuite/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Runtime.CompilerServices;

#if NET5_0_OR_GREATER
[module: SkipLocalsInit]
#endif
7 changes: 2 additions & 5 deletions src/Npgsql.NodaTime/Npgsql.NodaTime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
<Description>NodaTime plugin for Npgsql, allowing mapping of PostgreSQL date/time types to NodaTime types.</Description>
<PackageTags>npgsql;postgresql;postgres;nodatime;date;time;ado;ado;net;database;sql</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<TargetFrameworks Condition="'$(DeveloperBuild)' != 'True'">netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition="'$(DeveloperBuild)' == 'True'">net8.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition="'$(DeveloperBuild)' == 'True'">net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NodaTime" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
</ItemGroup>

Expand Down
2 changes: 0 additions & 2 deletions src/Npgsql.NodaTime/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Runtime.CompilerServices;

#if NET5_0_OR_GREATER
[module: SkipLocalsInit]
#endif

[assembly: InternalsVisibleTo("Npgsql.PluginTests, PublicKey=" +
"0024000004800000940000000602000000240000525341310004000001000100" +
Expand Down
2 changes: 1 addition & 1 deletion src/Npgsql.OpenTelemetry/Npgsql.OpenTelemetry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Authors>Shay Rojansky</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition="'$(DeveloperBuild)' == 'True'">net8.0</TargetFramework>
<PackageTags>npgsql;postgresql;postgres;ado;ado.net;database;sql;opentelemetry;tracing;diagnostics;instrumentation</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
2 changes: 0 additions & 2 deletions src/Npgsql.OpenTelemetry/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Runtime.CompilerServices;

#if NET5_0_OR_GREATER
[module: SkipLocalsInit]
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ protected ValueTask ReadAsObject(bool async, PgConverter converter, CompositeBui
else
AddValue(builder, converter.ReadAsObject(reader));
return new();
#if NET6_0_OR_GREATER

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
#endif
async ValueTask Core(CompositeBuilder builder, ValueTask<object> task)
{
builder.AddValue(await task.ConfigureAwait(false));
Expand Down Expand Up @@ -221,9 +220,7 @@ public override ValueTask Read(bool async, PgConverter converter, CompositeBuild
builder.AddValue(((PgConverter<T>)converter).Read(reader));
return new();

#if NET6_0_OR_GREATER
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
#endif
async ValueTask Core(CompositeBuilder builder, ValueTask<T> task)
{
builder.AddValue(await task.ConfigureAwait(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ static Delegate CreateSetter<T>(PropertyInfo info)
static Expression UnboxAny(Expression expression, Type type)
=> type.IsValueType ? Expression.Unbox(expression, type) : Expression.Convert(expression, type, null);

#if !NETSTANDARD
[DynamicDependency("TypedValue", typeof(StrongBox<>))]
[DynamicDependency("Length", typeof(StrongBox[]))]
#endif
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "DynamicDependencies in place for the System.Linq.Expression.Property calls")]
static Func<StrongBox[], T> CreateStrongBoxConstructor<T>(ConstructorInfo constructorInfo)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Npgsql/Internal/Converters/ArrayConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ public override ValueTask WriteAsync(PgWriter writer, T values, CancellationToke
// The alternatives are:
// 1. Add a virtual method and make AwaitTask call into it (bloating the vtable of all derived types).
// 2. Using a delegate, meaning we add a static field + an alloc per T + metadata, slightly slower dispatch perf so overall strictly worse as well.
#if NET6_0_OR_GREATER
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
#endif
private protected static async ValueTask AwaitTask(Task task, Continuation continuation, object collection, int[] indices)
{
await task.ConfigureAwait(false);
Expand Down
5 changes: 1 addition & 4 deletions src/Npgsql/Internal/Converters/AsyncHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ abstract class CompletionSource

sealed class CompletionSource<T> : CompletionSource
{
#if NETSTANDARD
AsyncValueTaskMethodBuilder<T> _amb = AsyncValueTaskMethodBuilder<T>.Create();
#else
PoolingAsyncValueTaskMethodBuilder<T> _amb = PoolingAsyncValueTaskMethodBuilder<T>.Create();
#endif

public ValueTask<T> Task => _amb.Task;

public void SetResult(T value)
Expand Down
14 changes: 2 additions & 12 deletions src/Npgsql/Internal/Converters/JsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,11 @@ public static bool TryReadStream(bool jsonb, Encoding encoding, PgReader reader,
var isUtf8 = encoding.CodePage == Encoding.UTF8.CodePage;
byteCount = reader.CurrentRemaining;
// We always fall back to buffers on older targets
if (isUtf8
#if !NETSTANDARD
|| byteCount >= StreamingThreshold
#endif
)
if (isUtf8 || byteCount >= StreamingThreshold)
{
stream =
#if !NETSTANDARD
!isUtf8
stream = !isUtf8
? Encoding.CreateTranscodingStream(reader.GetStream(), encoding, Encoding.UTF8)
: reader.GetStream();
#else
reader.GetStream();
Debug.Assert(isUtf8);
#endif
}
else
stream = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ internal static (IPAddress Address, byte Netmask) ReadImpl(PgReader reader, bool
var numBytes = reader.ReadByte();
Span<byte> bytes = stackalloc byte[numBytes];
reader.Read(bytes);
#if NETSTANDARD2_0
return (new IPAddress(bytes.ToArray()), mask);
#else
return (new IPAddress(bytes), mask);
#endif
}

protected override void WriteCore(PgWriter writer, NpgsqlInet value)
Expand Down
6 changes: 0 additions & 6 deletions src/Npgsql/Internal/Converters/Primitive/ByteaConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public override void Write(PgWriter writer, T value)
public override ValueTask WriteAsync(PgWriter writer, T value, CancellationToken cancellationToken = default)
=> writer.WriteBytesAsync(ConvertTo(value), cancellationToken);

#if NET6_0_OR_GREATER
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
#endif
async ValueTask<T> Read(bool async, PgReader reader, CancellationToken cancellationToken)
{
var bytes = new byte[reader.CurrentRemaining];
Expand Down Expand Up @@ -145,11 +143,7 @@ public override ValueTask WriteAsync(PgWriter writer, Stream value, Cancellation
}
else
{
#if NETSTANDARD2_0
return new ValueTask(value.CopyToAsync(writer.GetStream()));
#else
return new ValueTask(value.CopyToAsync(writer.GetStream(), cancellationToken));
#endif
}
}
}
44 changes: 0 additions & 44 deletions src/Npgsql/Internal/Converters/Primitive/PgMoney.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,55 +50,11 @@ static void GetDecimalBits(decimal value, Span<uint> destination, out short scal
{
Debug.Assert(destination.Length >= DecimalBits);

#if NETSTANDARD
var raw = new DecimalRaw(value);
destination[0] = raw.Low;
destination[1] = raw.Mid;
destination[2] = raw.High;
destination[3] = (uint)raw.Flags;
scale = raw.Scale;
#else
decimal.GetBits(value, MemoryMarshal.Cast<uint, int>(destination));
#endif
#if NET7_0_OR_GREATER
scale = value.Scale;
#else
scale = (byte)(destination[3] >> 16);
#endif
}

#if NETSTANDARD
// Zero-alloc access to the decimal bits on netstandard.
[StructLayout(LayoutKind.Explicit)]
readonly struct DecimalRaw
{
const int ScaleMask = 0x00FF0000;
const int ScaleShift = 16;

// Do not change the order in which these fields are declared. It
// should be same as in the System.Decimal.DecCalc struct.
[FieldOffset(0)]
readonly decimal _value;
[FieldOffset(0)]
readonly int _flags;
[FieldOffset(4)]
readonly uint _high;
[FieldOffset(8)]
readonly ulong _low64;

// Convenience aliased fields but their usage needs to take endianness into account.
[FieldOffset(8)]
readonly uint _low;
[FieldOffset(12)]
readonly uint _mid;

public DecimalRaw(decimal value) : this() => _value = value;

public uint High => _high;
public uint Mid => BitConverter.IsLittleEndian ? _mid : _low;
public uint Low => BitConverter.IsLittleEndian ? _low : _mid;
public int Flags => _flags;
public short Scale => (short)((_flags & ScaleMask) >> ScaleShift);
}
#endif
}
Loading
X Tutup