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
13 changes: 11 additions & 2 deletions src/Npgsql/Internal/Converters/Networking/IPNetworkConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System;
using System.Net;

// ReSharper disable once CheckNamespace
namespace Npgsql.Internal.Converters;
Expand All @@ -18,5 +19,13 @@ protected override IPNetwork ReadCore(PgReader reader)
}

protected override void WriteCore(PgWriter writer, IPNetwork value)
=> NpgsqlInetConverter.WriteImpl(writer, (value.BaseAddress, (byte)value.PrefixLength), isCidr: true);
=> NpgsqlInetConverter.WriteImpl(
writer,
(
value.BaseAddress,
value.PrefixLength <= byte.MaxValue
? (byte)value.PrefixLength
: throw new ArgumentOutOfRangeException(nameof(value), "IPNetwork.PrefixLength is too large to fit in a byte")
),
isCidr: true);
}
7 changes: 7 additions & 0 deletions src/Npgsql/NpgsqlTypes/NpgsqlTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ public static explicit operator IPAddress(NpgsqlInet inet)
public static implicit operator NpgsqlInet(IPAddress ip)
=> new(ip);

public static implicit operator NpgsqlInet(IPNetwork cidr)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mirrors the implicit cast we already had from the now-obsolete NpgsqlCidr (which was replaced by IPNetwork).

=> new(
cidr.BaseAddress,
cidr.PrefixLength <= byte.MaxValue
? (byte)cidr.PrefixLength
: throw new ArgumentOutOfRangeException(nameof(cidr), "IPNetwork.PrefixLength is too large to fit in a byte"));

public void Deconstruct(out IPAddress address, out byte netmask)
{
address = Address;
Expand Down
1 change: 1 addition & 0 deletions src/Npgsql/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ Npgsql.NpgsqlConnection.ReloadTypesAsync(System.Threading.CancellationToken canc
*REMOVED*Npgsql.NpgsqlSlimDataSourceBuilder.MapComposite<T>(string? pgName = null, Npgsql.INpgsqlNameTranslator? nameTranslator = null) -> Npgsql.TypeMapping.INpgsqlTypeMapper!
*REMOVED*Npgsql.NpgsqlSlimDataSourceBuilder.MapEnum(System.Type! clrType, string? pgName = null, Npgsql.INpgsqlNameTranslator? nameTranslator = null) -> Npgsql.TypeMapping.INpgsqlTypeMapper!
*REMOVED*Npgsql.NpgsqlSlimDataSourceBuilder.MapEnum<TEnum>(string? pgName = null, Npgsql.INpgsqlNameTranslator? nameTranslator = null) -> Npgsql.TypeMapping.INpgsqlTypeMapper!
static NpgsqlTypes.NpgsqlInet.implicit operator NpgsqlTypes.NpgsqlInet(System.Net.IPNetwork cidr) -> NpgsqlTypes.NpgsqlInet
static readonly NpgsqlTypes.NpgsqlTsVector.Empty -> NpgsqlTypes.NpgsqlTsVector!
X Tutup