PgCidr
Namespace: Ankus
Assembly: Ankus.Runtime.dll
An immutable PostgreSQL cidr network. Host bits must be zero; the default is 0.0.0.0/0.
[JsonConverter(typeof(PgCidrConverter))]public readonly struct PgCidr : IComparable<PgCidr>, ISpanFormattable, IFormattable, IParsable<PgCidr>, IEquatable<PgCidr>Implements: IComparable<PgCidr>, ISpanFormattable, IFormattable, IParsable<PgCidr>, IEquatable<PgCidr>
Constructors
Section titled “Constructors”PgCidr(PgInet)
Section titled “PgCidr(PgInet)”Creates a network from an inet value whose host bits are already zero. Use PgInet.Network to explicitly clear host bits first.
public PgCidr(PgInet value)Parameters:
value — PgInet
The network value.
PgCidr(IPAddress, int)
Section titled “PgCidr(IPAddress, int)”Creates a network without silently discarding host bits.
public PgCidr(IPAddress address, int prefixLength)Parameters:
address — IPAddress
The network address.
prefixLength — int
The network prefix length.
PgCidr(IPNetwork)
Section titled “PgCidr(IPNetwork)”Copies a .NET IPNetwork, rejecting scoped IPv6 addresses.
public PgCidr(IPNetwork network)Parameters:
network — IPNetwork
The network to copy.
Properties
Section titled “Properties”Address
Section titled “Address”Gets a detached copy of the network address.
public IPAddress Address { get; }Value: IPAddress
Gets this network as an inet value without information loss.
public PgInet Inet { get; }Value: PgInet
PrefixLength
Section titled “PrefixLength”Gets the number of network bits.
public int PrefixLength { get; }Value: int
Methods
Section titled “Methods”CompareTo(PgCidr)
Section titled “CompareTo(PgCidr)”Compares using PostgreSQL network ordering.
public int CompareTo(PgCidr other)Parameters:
other — PgCidr
The network to compare.
Returns: int
The comparison result.
Equals(PgCidr)
Section titled “Equals(PgCidr)”public bool Equals(PgCidr other)Parameters:
other — PgCidr
Returns: bool
Equals(object)
Section titled “Equals(object)”public override bool Equals(object obj)Parameters:
obj — object
Returns: bool
GetHashCode()
Section titled “GetHashCode()”public override int GetHashCode()Returns: int
Parse(string)
Section titled “Parse(string)”Parses PostgreSQL cidr text on the active backend, enforcing zero host bits.
public static PgCidr Parse(string text)Parameters:
text — string
The network text.
Returns: PgCidr
The parsed network.
ToIPNetwork()
Section titled “ToIPNetwork()”Converts to a .NET IPNetwork without loss of address family or prefix.
public IPNetwork ToIPNetwork()Returns: IPNetwork
The equivalent .NET network.
ToString()
Section titled “ToString()”Formats a detached network with an explicit prefix, without backend access.
public override string ToString()Returns: string
The round-trippable network text.
ToString(string?, IFormatProvider?)
Section titled “ToString(string?, IFormatProvider?)”Formats the value as PostgreSQL’s canonical text, the same text as ToString().
public string ToString(string? format, IFormatProvider? formatProvider)Parameters:
format — string
Null or empty; PostgreSQL text has one canonical form.
formatProvider — IFormatProvider
Ignored: the text does not depend on culture.
Returns: string
The canonical text.
Exceptions:
- FormatException: A format is specified.
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Section titled “TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)”Copies the value’s canonical PostgreSQL text into a span, as interpolated strings and other span-based formatters request it.
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)Parameters:
destination — Span<char>
The span that receives the text.
charsWritten — int
The number of characters written.
format — ReadOnlySpan<char>
Empty; PostgreSQL text has one canonical form.
provider — IFormatProvider
Ignored: the text does not depend on culture.
Returns: bool
Whether the text fit in the destination.
Exceptions:
- FormatException: A format is specified.
TryParse(string?, out PgCidr)
Section titled “TryParse(string?, out PgCidr)”Tries backend parsing without swallowing backend-access or operational failures.
public static bool TryParse(string? text, out PgCidr value)Parameters:
text — string
The network text.
value — PgCidr
The parsed network, or default.
Returns: bool
Whether the text is valid.
Invalid input leaves no error pending: PostgreSQL 16 and later report it as a soft input error, and earlier majors roll back an internal subtransaction. Before PostgreSQL 16, transaction callbacks and parallel operations forbid that rollback; native errors there remain pending and throw PgException.
WithPrefixLength(int)
Section titled “WithPrefixLength(int)”Changes the prefix and clears any host bits exposed by the change, like set_masklen(cidr, integer).
public PgCidr WithPrefixLength(int prefixLength)Parameters:
prefixLength — int
The new prefix length.
Returns: PgCidr
The normalized network.
Operators
Section titled “Operators”operator ==(PgCidr, PgCidr)
Section titled “operator ==(PgCidr, PgCidr)”public static bool operator ==(PgCidr left, PgCidr right)Parameters:
left — PgCidr
right — PgCidr
Returns: bool
operator >(PgCidr, PgCidr)
Section titled “operator >(PgCidr, PgCidr)”Compares two networks in reverse PostgreSQL order.
public static bool operator >(PgCidr left, PgCidr right)Parameters:
left — PgCidr
right — PgCidr
Returns: bool
operator >=(PgCidr, PgCidr)
Section titled “operator >=(PgCidr, PgCidr)”Compares two networks in reverse PostgreSQL order, including equality.
public static bool operator >=(PgCidr left, PgCidr right)Parameters:
left — PgCidr
right — PgCidr
Returns: bool
operator !=(PgCidr, PgCidr)
Section titled “operator !=(PgCidr, PgCidr)”public static bool operator !=(PgCidr left, PgCidr right)Parameters:
left — PgCidr
right — PgCidr
Returns: bool
operator <(PgCidr, PgCidr)
Section titled “operator <(PgCidr, PgCidr)”Compares two networks in PostgreSQL order.
public static bool operator <(PgCidr left, PgCidr right)Parameters:
left — PgCidr
right — PgCidr
Returns: bool
operator <=(PgCidr, PgCidr)
Section titled “operator <=(PgCidr, PgCidr)”Compares two networks in PostgreSQL order, including equality.
public static bool operator <=(PgCidr left, PgCidr right)Parameters:
left — PgCidr
right — PgCidr
Returns: bool