Table of Contents

Class ServerLocationInfo

Namespace
VpnHood.Core.Common.Tokens
Assembly
VpnHood.Core.Common.dll

Represents a server location: a country, a region in it, and tags, written as US/California [#premium].

public class ServerLocationInfo : IComparable<ServerLocationInfo>
Inheritance
ServerLocationInfo
Implements
Inherited Members

Remarks

Two locations are equal when their countries and regions are, whatever their tags.

Fields

AutoCountryCode

The country code of the automatic location: *.

public const string AutoCountryCode = "*"

Field Value

string

AutoRegionName

The region name of the automatic location, or of any region: *.

public const string AutoRegionName = "*"

Field Value

string

Properties

CountryCode

Gets the country's two-letter code, or AutoCountryCode.

public required string CountryCode { get; init; }

Property Value

string

CountryName

Gets the country's English name; * for the automatic location, and the code in upper case where .NET knows no country of it.

public string CountryName { get; }

Property Value

string

HasRegion

Gets a value indicating whether the location names a region.

public bool HasRegion { get; }

Property Value

bool

IsAuto

Gets a value indicating whether this is the automatic location, /.

public bool IsAuto { get; }

Property Value

bool

RegionName

Gets the region's name, or AutoRegionName.

public required string RegionName { get; init; }

Property Value

string

ServerLocation

Gets the location without its tags, as US/California.

public string ServerLocation { get; }

Property Value

string

Tags

Gets or sets the location's tags, such as those of ServerRegisteredTags, or null.

public string[]? Tags { get; set; }

Property Value

string[]

Methods

CompareTo(ServerLocationInfo?)

Compares the location with another, by country name, then region name, ignoring case.

public int CompareTo(ServerLocationInfo? other)

Parameters

other ServerLocationInfo

The other location, or null, which sorts first.

Returns

int

Less than 0 if this location sorts first, 0 if they sort together, more than 0 if it sorts after.

Equals(object?)

Determines whether an object is a location of the same country and region.

public override bool Equals(object? obj)

Parameters

obj object

The object.

Returns

bool

true if it is; otherwise, false.

Remarks

The codes and names are compared as written, case included.

GetHashCode()

Gets a hash of the location's country and region.

public override int GetHashCode()

Returns

int

The hash.

IsAutoLocation(string?)

Determines whether a written location is the automatic one.

public static bool IsAutoLocation(string? serverLocation)

Parameters

serverLocation string

The written location.

Returns

bool

true if it is null, empty, or reads as /; otherwise, false.

IsMatch(ServerLocationInfo)

Determines whether this location, a server's, matches a location asked for, whose * parts match any.

public bool IsMatch(ServerLocationInfo serverLocationInfo)

Parameters

serverLocationInfo ServerLocationInfo

The location asked for.

Returns

bool

true if it matches, ignoring case; otherwise, false.

LocationEquals(string?)

Determines whether a written location is this one, as Equals(object?) compares them.

public bool LocationEquals(string? serverLocation)

Parameters

serverLocation string

The written location, or null, which equals the automatic one.

Returns

bool

true if it is; otherwise, false.

Parse(string)

Reads a location written as CountryCode/RegionName [#tag1 #tag2].

public static ServerLocationInfo Parse(string value)

Parameters

value string

The text. A missing or blank country or region reads as *; the country code is made upper case; the tags, in brackets, are split at spaces.

Returns

ServerLocationInfo

The location.

ToString()

Writes the location as Parse(string) reads it, with its tags in brackets when it has any.

public override string ToString()

Returns

string

The text, such as US/California [#premium].

TryParse(string)

Reads a location as Parse(string) does, or gives null where that throws.

public static ServerLocationInfo? TryParse(string value)

Parameters

value string

The text.

Returns

ServerLocationInfo

The location, or null.