Make the cidr<->IPNetwork mapping the default (#5950) · npgsql/npgsql@a1f1022 · GitHub
Skip to content

Commit a1f1022

Browse files
authored
Make the cidr<->IPNetwork mapping the default (#5950)
Closes #5891
1 parent d606795 commit a1f1022

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

‎src/Npgsql/Internal/Converters/Networking/NpgsqlCidrConverter.cs‎

Lines changed: 2 additions & 0 deletions

‎src/Npgsql/Internal/ResolverFactories/NetworkTypeInfoResolverFactory.cs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ static TypeInfoMappingCollection AddMappings(TypeInfoMappingCollection mappings)
4848
static (options, mapping, _) => mapping.CreateInfo(options, new NpgsqlInetConverter()));
4949

5050
// cidr
51-
mappings.AddStructType<NpgsqlCidr>(DataTypeNames.Cidr,
52-
static (options, mapping, _) => mapping.CreateInfo(options, new NpgsqlCidrConverter()), isDefault: true);
53-
5451
mappings.AddStructType<IPNetwork>(DataTypeNames.Cidr,
55-
static (options, mapping, _) => mapping.CreateInfo(options, new IPNetworkConverter()));
52+
static (options, mapping, _) => mapping.CreateInfo(options, new IPNetworkConverter()), isDefault: true);
53+
54+
#pragma warning disable CS0618 // NpgsqlCidr is obsolete
55+
mappings.AddStructType<NpgsqlCidr>(DataTypeNames.Cidr,
56+
static (options, mapping, _) => mapping.CreateInfo(options, new NpgsqlCidrConverter()));
57+
#pragma warning restore CS0618
5658

5759
return mappings;
5860
}
@@ -77,8 +79,10 @@ static TypeInfoMappingCollection AddMappings(TypeInfoMappingCollection mappings)
7779
mappings.AddStructArrayType<NpgsqlInet>(DataTypeNames.Inet);
7880

7981
// cidr
80-
mappings.AddStructArrayType<NpgsqlCidr>(DataTypeNames.Cidr);
8182
mappings.AddStructArrayType<IPNetwork>(DataTypeNames.Cidr);
83+
#pragma warning disable CS0618 // NpgsqlCidr is obsolete
84+
mappings.AddStructArrayType<NpgsqlCidr>(DataTypeNames.Cidr);
85+
#pragma warning restore CS0618
8286

8387
return mappings;
8488
}

‎src/Npgsql/NpgsqlTypes/NpgsqlTypes.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ static void CheckAddressFamily(IPAddress address)
488488
/// <remarks>
489489
/// https://www.postgresql.org/docs/current/static/datatype-net-types.html
490490
/// </remarks>
491+
[Obsolete("Use .NET IPNetwork instead of NpgsqlCidr to map to PostgreSQL cidr")]
491492
public readonly record struct NpgsqlCidr
492493
{
493494
public IPAddress Address { get; }

‎test/Npgsql.Tests/Types/NetworkTypeTests.cs‎

Lines changed: 7 additions & 7 deletions

0 commit comments

Comments
 (0)