Struct JoinCode

Namespace
Unity.Multiplayer.Core

A validated join code: MinDataLength–MaxDataLength data characters plus one check character, all from Alphabet.

public readonly struct JoinCode : IEquatable<JoinCode>
Implements
Inherited Members

Remarks

Every non-empty instance is valid: the only ways to get one are Parse(string) / TryParse(string, out JoinCode), FromData(string) and Generate(). default(JoinCode) is the empty code (IsEmpty). Equality compares the canonical form, so abcd-efgh and ABCDEFGH parse to equal codes.

Properties

CheckCharacter

The check character, or '\0' for Empty.

public char CheckCharacter { get; }

Property Value

char

Data

The data characters, without the check character.

public string Data { get; }

Property Value

string

Empty

The empty code, the same as default(JoinCode).

public static JoinCode Empty { get; }

Property Value

JoinCode

IsEmpty

True for default(JoinCode).

public bool IsEmpty { get; }

Property Value

bool

Length

Total characters, the check character included.

public int Length { get; }

Property Value

int

Value

The canonical form: upper case, no separators, check character last. Empty for Empty.

public string Value { get; }

Property Value

string

Methods

Equals(object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Equals(JoinCode)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(JoinCode other)

Parameters

other JoinCode

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

FromData(string)

Builds a code from data characters by appending their check character. Input is normalized first (case, separators), but look-alikes are not corrected: this is for data a program produced, not for player input.

public static JoinCode FromData(string data)

Parameters

data string

Returns

JoinCode

Exceptions

ArgumentNullException

data is null.

ArgumentException

The data length is out of range or a character is outside the alphabet.

Generate()

Generates a random code with DefaultDataLength data characters from a cryptographic RNG.

public static JoinCode Generate()

Returns

JoinCode

Generate(int)

Generates a random code with dataLength data characters from a cryptographic RNG.

public static JoinCode Generate(int dataLength)

Parameters

dataLength int

Returns

JoinCode

Exceptions

ArgumentOutOfRangeException

dataLength is out of range.

Generate(int, RandomNumberGenerator)

Generates a random code with dataLength data characters, drawing bytes from rng. Each byte's low 5 bits pick a symbol, so every symbol is equally likely.

public static JoinCode Generate(int dataLength, RandomNumberGenerator rng)

Parameters

dataLength int
rng RandomNumberGenerator

Returns

JoinCode

Exceptions

ArgumentNullException

rng is null.

ArgumentOutOfRangeException

dataLength is out of range.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Parse(string)

Parses player input, tolerating case, separators and one look-alike character.

public static JoinCode Parse(string input)

Parameters

input string

Returns

JoinCode

Exceptions

FormatException

The input is not a valid join code; the message says why.

ToString()

The code grouped for display, ABC-EFG-HJK; empty for Empty.

public override string ToString()

Returns

string

TryParse(string, out JoinCode)

Parses player input, tolerating case, separators and one look-alike character.

public static bool TryParse(string input, out JoinCode code)

Parameters

input string
code JoinCode

Returns

bool

TryParse(string, out JoinCodeParseResult)

Parses player input, tolerating case, separators and one look-alike character, and reports why it failed (or that a look-alike was corrected) in result.

public static bool TryParse(string input, out JoinCodeParseResult result)

Parameters

input string
result JoinCodeParseResult

Returns

bool

Operators

operator ==(JoinCode, JoinCode)

True when both codes have the same canonical form.

public static bool operator ==(JoinCode left, JoinCode right)

Parameters

left JoinCode
right JoinCode

Returns

bool

operator !=(JoinCode, JoinCode)

True when the codes differ.

public static bool operator !=(JoinCode left, JoinCode right)

Parameters

left JoinCode
right JoinCode

Returns

bool