Class PortRange
Represents a range of ports, from a first to a last port, both included.
[JsonConverter(typeof(PortRangeConverter))]
public record PortRange : IEquatable<PortRange>
- Inheritance
-
PortRange
- Implements
- Inherited Members
Remarks
Its text form is 8000-8100, or the port alone for a range of one port, and JSON reads and writes a range as
that text, through PortRangeConverter. Two instances of PortRange itself are equal when
their first and last ports are.
Constructors
PortRange(int)
Initializes a new instance of the PortRange class that holds one port.
public PortRange(int port)
Parameters
portintThe port, from 0 to 65535.
Exceptions
- ArgumentOutOfRangeException
portis below 0 or above 65535.
PortRange(int, int)
Initializes a new instance of the PortRange class.
public PortRange(int firstPort, int lastPort)
Parameters
Exceptions
- ArgumentOutOfRangeException
firstPortis below 0,lastPortis above 65535, orfirstPortis abovelastPort.
Properties
FirstPort
Gets the range's first port.
public int FirstPort { get; }
Property Value
LastPort
Gets the range's last port.
public int LastPort { get; }
Property Value
Methods
IsInRange(int)
Determines whether a port is in the range.
public bool IsInRange(int port)
Parameters
portintThe port.
Returns
Parse(string)
Converts the text form of a range, such as 8000-8100, to a PortRange.
public static PortRange Parse(string value)
Parameters
valuestringA port (
443) or two ports joined by-(8000-8100), in decimal digits; white space around a port is allowed.
Returns
- PortRange
The range.
Exceptions
- FormatException
valueis neither form, or a port is not decimal digits or is above MaxValue.- ArgumentOutOfRangeException
A port is from 65536 to MaxValue, or the first is above the last.
ToString()
Returns the range's text form: 8000-8100, or the port alone when the range holds one port.
public override string ToString()
Returns
- string
The text.