public class Name : IComparable<Name>, IEquatable<Name>
A name is used to uniquely identify a specific item or node. It is a combination of a text label and an optional integer index.

Constructors

Name

#
public Name(string label, int index)
Constructor for names with indices.
label (string)Label of name.
index (int)Index of name. Valid values are:

-1 = no index

0 to int.MaxValue = valid index

Name

#
public Name(string label)
Constuctor for names without an index.
label (string)Label of name.

Fields

Empty

#
public static readonly Name Empty
Gets a sensible placeholder name. Placeholders can be used if you do not care about the name, or if the node is about to be deserialised anyway.

Properties

Index

#
public int Index { get; }
Gets the index of this name. An index of -1 indicates no index is implied.

IsIndexed

#
public bool IsIndexed { get; }
Gets whether the index has been set.

Label

#
public string Label { get; }
Gets the label of this name.

Methods

CompareTo

#
public int CompareTo(Name other)
Compare two names.
other (Name)ID to compare to.
Comparison code.

Equals

#
public bool Equals(Name other)
Compare two names for equality.
other (Name)ID to compare to.
True if both IDs are identical.

Equals

#
public override bool Equals(object obj)
Compare two names for equality.
obj (object)ID to compare to.
True if the IDs are identical.
Object.Equals

GetHashCode

#
public override int GetHashCode()
Gets the hash code for this name.
Hash.

IsAllowedChar

#
public static bool IsAllowedChar(char c)
Tests whether a specific char is allowed in a name label. Most latinate upper and lower case letters are allowed, as well as some symbols such as underscores, periods, colons and braces.
c (char)Character to test.
True if character is allowed.

IsAllowedLabel

#
public static bool IsAllowedLabel(string label, out string violation)
Tests whether a string is a valid name label.
label (string)String to test.
violation (out string)Violation (if any).
True if label is valid.

ToString

#
public override string ToString()
Gets a string representation for this name.
Object.ToString

WithIndex

#
public Name WithIndex(int index)
Change the index of this name. This is slightly quicker than creating a new Name from scratch as it skips label validation.
index (int)New index.

Operators

OperationResultDescription
Name==Namebool
Name!=Namebool

Convertors

OperationResultDescription
implicitstringNameWidening conversion operator from string to name. If the text ends with a hash followed by an integer constant, it is interpreted as the index.