Table of Contents

Class PortRange

Namespace
VpnHood.Net.Toolkit.Net
Assembly
VpnHood.Net.Toolkit.dll

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

port int

The port, from 0 to 65535.

Exceptions

ArgumentOutOfRangeException

port is below 0 or above 65535.

PortRange(int, int)

Initializes a new instance of the PortRange class.

public PortRange(int firstPort, int lastPort)

Parameters

firstPort int

The first port, from 0 to 65535.

lastPort int

The last port, from firstPort to 65535.

Exceptions

ArgumentOutOfRangeException

firstPort is below 0, lastPort is above 65535, or firstPort is above lastPort.

Properties

FirstPort

Gets the range's first port.

public int FirstPort { get; }

Property Value

int

LastPort

Gets the range's last port.

public int LastPort { get; }

Property Value

int

Methods

IsInRange(int)

Determines whether a port is in the range.

public bool IsInRange(int port)

Parameters

port int

The port.

Returns

bool

true if the range holds the port; otherwise, false.

Parse(string)

Converts the text form of a range, such as 8000-8100, to a PortRange.

public static PortRange Parse(string value)

Parameters

value string

A 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

value is 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.