Class NbtTag
- Namespace
- fNbt
- Assembly
- fNbt.dll
Base class for different kinds of named binary tags.
public abstract class NbtTag : ICloneable
- Inheritance
-
NbtTag
- Implements
- Derived
- Inherited Members
Properties
ByteArrayValue
Returns the value of this tag, cast as a byte array. Only supported by NbtByteArray tags.
public byte[] ByteArrayValue { get; }
Property Value
- byte[]
Exceptions
- InvalidCastException
When used on a tag other than NbtByteArray.
ByteValue
Returns the value of this tag, cast as a byte. Only supported by NbtByte tags.
public byte ByteValue { get; }
Property Value
Exceptions
- InvalidCastException
When used on a tag other than NbtByte.
DefaultIndentString
String to use for indentation in NbtTag's and NbtFile's ToString() methods by default.
public static string DefaultIndentString { get; set; }
Property Value
Exceptions
- ArgumentNullException
valueisnull.
DoubleValue
Returns the value of this tag, cast as a long (64-bit signed integer). Only supported by NbtFloat, NbtDouble, and, with loss of precision, by NbtByte, NbtShort, NbtInt, and NbtLong.
public double DoubleValue { get; }
Property Value
Exceptions
- InvalidCastException
When used on an unsupported tag.
FloatValue
Returns the value of this tag, cast as a long (64-bit signed integer). Only supported by NbtFloat and, with loss of precision, by NbtDouble, NbtByte, NbtShort, NbtInt, and NbtLong.
public float FloatValue { get; }
Property Value
Exceptions
- InvalidCastException
When used on an unsupported tag.
HasValue
Returns true if tags of this type have a value attached. All tags except Compound, List, and End have values.
public bool HasValue { get; }
Property Value
IntArrayValue
Returns the value of this tag, cast as an int array. Only supported by NbtIntArray tags.
public int[] IntArrayValue { get; }
Property Value
- int[]
Exceptions
- InvalidCastException
When used on a tag other than NbtIntArray.
IntValue
Returns the value of this tag, cast as an int (32-bit signed integer). Only supported by NbtByte, NbtShort, and NbtInt.
public int IntValue { get; }
Property Value
Exceptions
- InvalidCastException
When used on an unsupported tag.
this[int]
Gets or sets the tag at the specified index.
public virtual NbtTag this[int tagIndex] { get; set; }
Parameters
tagIndexintThe zero-based index of the tag to get or set.
Property Value
- NbtTag
The tag at the specified index.
Remarks
ONLY APPLICABLE TO NbtList, NbtByteArray, and NbtIntArray OBJECTS! Included in NbtTag base class for programmers' convenience, to avoid extra type casts.
Exceptions
- ArgumentOutOfRangeException
tagIndex is not a valid index in this tag.
- ArgumentNullException
Given tag is
null.- ArgumentException
Given tag's type does not match ListType.
- InvalidOperationException
If used on a tag that is not NbtList, NbtByteArray, or NbtIntArray.
this[string]
Gets or sets the tag with the specified name. May return null.
public virtual NbtTag? this[string tagName] { get; set; }
Parameters
tagNamestringThe name of the tag to get or set. Must match tag's actual name.
Property Value
- NbtTag
The tag with the specified key. Null if tag with the given name was not found.
Remarks
ONLY APPLICABLE TO NbtCompound OBJECTS! Included in NbtTag base class for programmers' convenience, to avoid extra type casts.
Exceptions
- InvalidOperationException
If used on a tag that is not NbtCompound.
LongArrayValue
Returns the value of this tag, cast as a long array. Only supported by NbtLongArray tags.
public long[] LongArrayValue { get; }
Property Value
- long[]
Exceptions
- InvalidCastException
When used on a tag other than NbtLongArray.
LongValue
Returns the value of this tag, cast as a long (64-bit signed integer). Only supported by NbtByte, NbtShort, NbtInt, and NbtLong.
public long LongValue { get; }
Property Value
Exceptions
- InvalidCastException
When used on an unsupported tag.
Name
Name of this tag. Immutable, and set by the constructor. May be null.
public string? Name { get; set; }
Property Value
Exceptions
- ArgumentNullException
If
valueisnull, andParenttag is an NbtCompound. Name of tags inside anNbtCompoundmay not be null.- ArgumentException
If this tag resides in an
NbtCompound, and a sibling tag with the name already exists.
Parent
Parent compound tag, either NbtList or NbtCompound, if any.
May be null for detached tags.
public NbtTag? Parent { get; }
Property Value
Path
Gets the full name of this tag, including all parent tag names, separated by dots. Unnamed tags show up as empty strings.
public string Path { get; }
Property Value
ShortValue
Returns the value of this tag, cast as a short (16-bit signed integer). Only supported by NbtByte and NbtShort.
public short ShortValue { get; }
Property Value
Exceptions
- InvalidCastException
When used on an unsupported tag.
StringValue
Returns the value of this tag, cast as a string. Returns exact value for NbtString, and stringified (using InvariantCulture) value for NbtByte, NbtDouble, NbtFloat, NbtInt, NbtLong, and NbtShort. Not supported by NbtCompound, NbtList, NbtByteArray, NbtIntArray, or NbtLongArray.
public string StringValue { get; }
Property Value
Exceptions
- InvalidCastException
When used on an unsupported tag.
TagType
Type of this tag.
public abstract NbtTagType TagType { get; }
Property Value
Methods
Clone()
Creates a deep copy of this tag.
public abstract object Clone()
Returns
- object
A new NbtTag object that is a deep copy of this instance.
GetCanonicalTagName(NbtTagType)
Returns a canonical (Notchy) name for the given NbtTagType, e.g. "TAG_Byte_Array" for NbtTagType.ByteArray
public static string? GetCanonicalTagName(NbtTagType type)
Parameters
typeNbtTagTypeNbtTagType to name.
Returns
- string
String representing the canonical name of a tag, or null of given TagType does not have a canonical name (e.g. Unknown).
ToString()
Prints contents of this tag, and any child tags, to a string. Indents the string using multiples of the given indentation string.
public override string ToString()
Returns
- string
A string representing contents of this tag, and all child tags (if any).
ToString(string)
Prints contents of this tag, and any child tags, to a string. Indents the string using multiples of the given indentation string.
public string ToString(string indentString)
Parameters
indentStringstringString to be used for indentation.
Returns
- string
A string representing contents of this tag, and all child tags (if any).
Exceptions
- ArgumentNullException
indentStringisnull.