NbtTag
abstract class
Represents a named binary tag. This class is abstract.
Declaration
public abstract class NbtTag
| Namespace | McProtoNet.NBT |
| Assembly | McProtoNet.NBT.dll |
| Source | src/McProtoNet.NBT/Tags/NbtTag.cs#L9 ↗ |
Derived: NbtByte, NbtByteArray, NbtCompound, NbtDouble, NbtFloat, NbtInt, NbtIntArray, NbtList, NbtLong, NbtLongArray, NbtShort, NbtString
Properties
| Signature | Description |
|---|---|
bool BoolValue | Gets a value indicating whether the value of this tag is nonzero. |
byte[] ByteArrayValue | Gets the value of this tag as an array of bytes. |
byte ByteValue | Gets the value of this tag as a byte. |
static string DefaultIndentString | Gets or sets the string that NbtTag.ToString uses for one level of indentation. |
double DoubleValue | Gets the value of this tag as a double-precision floating-point number. |
float FloatValue | Gets the value of this tag as a single-precision floating-point number. |
bool HasValue | Gets a value indicating whether this tag carries a value. |
int[] IntArrayValue | Gets the value of this tag as an array of signed 32-bit integers. |
int IntValue | Gets the value of this tag as a signed 32-bit integer. |
NbtTag this[int tagIndex] | Gets or sets the tag at the specified index. |
NbtTag? this[string tagName] | Gets or sets the tag with the specified name. |
long[] LongArrayValue | Gets the value of this tag as an array of signed 64-bit integers. |
long LongValue | Gets the value of this tag as a signed 64-bit integer. |
string? Name | Gets or sets the name of this tag. |
NbtTag? Parent | Gets the tag that contains this tag. |
string Path | Gets the full name of this tag, which includes the names of all parent tags separated by periods. |
short ShortValue | Gets the value of this tag as a signed 16-bit integer. |
string StringValue | Gets the value of this tag as a string. |
NbtTagType TagType | When overridden in a derived class, gets the type of this tag. |
BoolValue
public bool BoolValue { get; }
Gets a value indicating whether the value of this tag is nonzero.
Returns: bool - true if the value of this tag is not 0; otherwise, false.
Exceptions: InvalidCastException - This tag is not an NbtByte.
ByteArrayValue
public byte[] ByteArrayValue { get; }
Gets the value of this tag as an array of bytes.
Returns: byte[] - The array held by this tag. The array is returned by reference and is not copied.
Exceptions: InvalidCastException - This tag is not an NbtByteArray.
ByteValue
public byte ByteValue { get; }
Gets the value of this tag as a byte.
Returns: byte - The value of this tag.
Exceptions: InvalidCastException - This tag is not an NbtByte.
DefaultIndentString
public static string DefaultIndentString { get; set; }
Gets or sets the string that NbtTag.ToString uses for one level of indentation.
Returns: string - The indentation string. The default is two spaces.
Exceptions: ArgumentNullException - The property is set to null.
DoubleValue
public double DoubleValue { get; }
Gets the value of this tag as a double-precision floating-point number.
Returns: double - The value of this tag, converted to a double-precision floating-point number. The conversion from NbtLong can lose precision.
Exceptions: InvalidCastException - This tag is not an NbtByte, an NbtShort, an NbtInt, an NbtLong, an NbtFloat or an NbtDouble.
FloatValue
public float FloatValue { get; }
Gets the value of this tag as a single-precision floating-point number.
Returns: float - The value of this tag, converted to a single-precision floating-point number. The conversion from NbtDouble, NbtInt and NbtLong can lose precision.
Exceptions: InvalidCastException - This tag is not an NbtByte, an NbtShort, an NbtInt, an NbtLong, an NbtFloat or an NbtDouble.
HasValue
public bool HasValue { get; }
Gets a value indicating whether this tag carries a value.
Returns: bool - true if the type of this tag is neither NbtTagType.Compound, NbtTagType.List nor NbtTagType.End; otherwise, false.
IntArrayValue
public int[] IntArrayValue { get; }
Gets the value of this tag as an array of signed 32-bit integers.
Returns: int[] - The array held by this tag. The array is returned by reference and is not copied.
Exceptions: InvalidCastException - This tag is not an NbtIntArray.
IntValue
public int IntValue { get; }
Gets the value of this tag as a signed 32-bit integer.
Returns: int - The value of this tag, converted to a signed 32-bit integer.
Exceptions: InvalidCastException - This tag is not an NbtByte, an NbtShort or an NbtInt.
this[int]
public virtual NbtTag this[int tagIndex] { get; set; }
Gets or sets the tag at the specified index.
Only NbtList overrides this indexer. It is declared on NbtTag so that a caller
does not have to cast. The array tags declare their own indexers over their element type.
Parameters: tagIndex (int)
Returns: NbtTag - The tag at the specified index.
Exceptions: ArgumentOutOfRangeException - tagIndex is not a valid index in this tag.; ArgumentNullException - The property is set to null.; ArgumentException - The type of the tag being set does not match NbtList.ListType.; InvalidOperationException - This tag is not an NbtList.
this[string]
public virtual NbtTag? this[string tagName] { get; set; }
Gets or sets the tag with the specified name.
Only NbtCompound overrides this indexer. It is declared on NbtTag so that a
caller does not have to cast.
Parameters: tagName (string)
Returns: NbtTag - The tag with the specified name, or null if no tag with that name is present.
Exceptions: InvalidOperationException - This tag is not an NbtCompound.
LongArrayValue
public long[] LongArrayValue { get; }
Gets the value of this tag as an array of signed 64-bit integers.
Returns: long[] - The array held by this tag. The array is returned by reference and is not copied.
Exceptions: InvalidCastException - This tag is not an NbtLongArray.
LongValue
public long LongValue { get; }
Gets the value of this tag as a signed 64-bit integer.
Returns: long - The value of this tag, converted to a signed 64-bit integer.
Exceptions: InvalidCastException - This tag is not an NbtByte, an NbtShort, an NbtInt or an NbtLong.
Name
public string? Name { get; set; }
Gets or sets the name of this tag.
Setting this property while the tag is contained in an NbtCompound also renames the entry in
that compound.
Returns: string - The name of this tag, or null if this tag is unnamed.
Exceptions: ArgumentNullException - The property is set to null while this tag is contained in an NbtCompound. A tag inside a compound must be named.; ArgumentException - This tag is contained in an NbtCompound that already holds a tag with the new name.
Parent
public NbtTag? Parent { get; }
Gets the tag that contains this tag.
Returns: NbtTag - The NbtCompound or NbtList that contains this tag, or null if this tag is not contained in another tag.
Path
public string Path { get; }
Gets the full name of this tag, which includes the names of all parent tags separated by periods.
Returns: string - The full name of this tag. An unnamed tag contributes an empty string; an element of an NbtList contributes its index in brackets.
ShortValue
public short ShortValue { get; }
Gets the value of this tag as a signed 16-bit integer.
Returns: short - The value of this tag, converted to a signed 16-bit integer.
Exceptions: InvalidCastException - This tag is neither an NbtByte nor an NbtShort.
StringValue
public string StringValue { get; }
Gets the value of this tag as a string.
Returns: string - The exact value for an NbtString; for a numeric tag, the value formatted with CultureInfo.InvariantCulture.
Exceptions: InvalidCastException - This tag is neither an NbtString nor a numeric tag.
TagType
public abstract NbtTagType TagType { get; }
When overridden in a derived class, gets the type of this tag.
Returns: NbtTagType
Fields
| Signature | Description |
|---|---|
static NbtTag EndTag | The tag that marks the end of a compound. |
EndTag
public static readonly NbtTag EndTag
The tag that marks the end of a compound. This field is read-only.
Returns: NbtTag
Methods
| Signature | Description |
|---|---|
object Clone() | When overridden in a derived class, creates a deep copy of this tag. |
static string? GetCanonicalTagName(NbtTagType type) | Returns the canonical name of the specified tag type, such as TAG_Byte_Array for NbtTagType.ByteArray. |
string ToString() | Returns a string that represents this tag and all its child tags, indented with NbtTag.DefaultIndentString. |
string ToString(string indentString) | Returns a string that represents this tag and all its child tags, indented with the specified string. |
Clone()
public abstract object Clone()
When overridden in a derived class, creates a deep copy of this tag.
Returns: object - A new NbtTag that is a deep copy of this instance. The copy has no parent.
GetCanonicalTagName(NbtTagType)
public static string? GetCanonicalTagName(NbtTagType type)
Returns the canonical name of the specified tag type, such as TAG_Byte_Array for
NbtTagType.ByteArray.
Parameters: type (NbtTagType)
Returns: string - The canonical name of the tag type, or null if type is not a recognized tag type.
ToString()
public override string ToString()
Returns a string that represents this tag and all its child tags, indented with
NbtTag.DefaultIndentString.
Returns: string - A string that represents this tag and all its child tags.
ToString(string)
public string ToString(string indentString)
Returns a string that represents this tag and all its child tags, indented with the specified string.
Parameters: indentString (string)
Returns: string - A string that represents this tag and all its child tags.
Exceptions: ArgumentNullException - indentString is null.