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
Data
The data characters, without the check character.
public string Data { get; }
Property Value
Empty
The empty code, the same as default(JoinCode).
public static JoinCode Empty { get; }
Property Value
IsEmpty
True for default(JoinCode).
public bool IsEmpty { get; }
Property Value
Length
Total characters, the check character included.
public int Length { get; }
Property Value
Value
The canonical form: upper case, no separators, check character last. Empty for Empty.
public string Value { get; }
Property Value
Methods
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
otherJoinCodeAn object to compare with this object.
Returns
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
datastring
Returns
Exceptions
- ArgumentNullException
datais 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
Generate(int)
Generates a random code with dataLength data characters from a cryptographic RNG.
public static JoinCode Generate(int dataLength)
Parameters
dataLengthint
Returns
Exceptions
- ArgumentOutOfRangeException
dataLengthis 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
dataLengthintrngRandomNumberGenerator
Returns
Exceptions
- ArgumentNullException
rngis null.- ArgumentOutOfRangeException
dataLengthis 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
inputstring
Returns
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
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
Returns
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
inputstringresultJoinCodeParseResult
Returns
Operators
operator ==(JoinCode, JoinCode)
True when both codes have the same canonical form.
public static bool operator ==(JoinCode left, JoinCode right)
Parameters
Returns
operator !=(JoinCode, JoinCode)
True when the codes differ.
public static bool operator !=(JoinCode left, JoinCode right)