Class NbtCompound
- Namespace
- fNbt
- Assembly
- fNbt.dll
A tag containing a set of other named tags. Order is not guaranteed.
public sealed class NbtCompound : NbtTag, ICloneable, ICollection<NbtTag>, IEnumerable<NbtTag>, ICollection, IEnumerable
- Inheritance
-
NbtCompound
- Implements
- Inherited Members
Constructors
NbtCompound()
Creates an empty unnamed NbtByte tag.
public NbtCompound()
NbtCompound(IEnumerable<NbtTag>)
Creates an unnamed NbtByte tag, containing the given tags.
public NbtCompound(IEnumerable<NbtTag> tags)
Parameters
tagsIEnumerable<NbtTag>Collection of tags to assign to this tag's Value. May not be null
Exceptions
- ArgumentNullException
tagsisnull, or one of the tags isnull.- ArgumentException
If some of the given tags were not named, or two tags with the same name were given.
NbtCompound(string?)
Creates an empty NbtByte tag with the given name.
public NbtCompound(string? tagName)
Parameters
tagNamestringName to assign to this tag. May be
null.
NbtCompound(string?, IEnumerable<NbtTag>)
Creates an NbtByte tag with the given name, containing the given tags.
public NbtCompound(string? tagName, IEnumerable<NbtTag> tags)
Parameters
tagNamestringName to assign to this tag. May be
null.tagsIEnumerable<NbtTag>Collection of tags to assign to this tag's Value. May not be null
Exceptions
- ArgumentNullException
tagsisnull, or one of the tags isnull.- ArgumentException
If some of the given tags were not named, or two tags with the same name were given.
NbtCompound(NbtCompound)
Creates a deep copy of given NbtCompound.
public NbtCompound(NbtCompound other)
Parameters
otherNbtCompoundAn existing NbtCompound to copy. May not be
null.
Exceptions
- ArgumentNullException
otherisnull.
Properties
Count
Gets the number of tags contained in the NbtCompound.
public int Count { get; }
Property Value
- int
The number of tags contained in the NbtCompound.
this[string]
Gets or sets the tag with the specified name. May return null.
public override 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.
Exceptions
- ArgumentNullException
tagNameisnull; or if trying to assign null value.- ArgumentException
tagNamedoes not match the given tag's actual name; or given tag already has a Parent.
Names
Gets a collection containing all tag names in this NbtCompound.
public IEnumerable<string> Names { get; }
Property Value
TagType
Type of this tag (Compound).
public override NbtTagType TagType { get; }
Property Value
Tags
Gets a collection containing all tags in this NbtCompound.
public IEnumerable<NbtTag> Tags { get; }
Property Value
Methods
Add(NbtTag)
Adds a tag to this NbtCompound.
public void Add(NbtTag newTag)
Parameters
newTagNbtTagThe object to add to this NbtCompound.
Exceptions
- ArgumentNullException
newTagisnull.- ArgumentException
If the given tag is unnamed; or if a tag with the given name already exists in this NbtCompound.
AddRange(IEnumerable<NbtTag>)
Adds all tags from the specified collection to this NbtCompound.
public void AddRange(IEnumerable<NbtTag> newTags)
Parameters
newTagsIEnumerable<NbtTag>The collection whose elements should be added to this NbtCompound.
Exceptions
- ArgumentNullException
newTagsisnull, or one of the tags in newTags isnull.- ArgumentException
If one of the given tags was unnamed, or if a tag with the given name already exists in this NbtCompound.
Clear()
Removes all tags from this NbtCompound.
public void Clear()
Clone()
Creates a deep copy of this tag.
public override object Clone()
Returns
- object
A new NbtTag object that is a deep copy of this instance.
Contains(string)
Determines whether this NbtCompound contains a tag with a specific name.
public bool Contains(string tagName)
Parameters
tagNamestringTag name to search for. May not be
null.
Returns
- bool
true if a tag with given name was found; otherwise, false.
Exceptions
- ArgumentNullException
tagNameisnull.
Contains(NbtTag)
Determines whether this NbtCompound contains a specific NbtTag. Looks for exact object matches, not name matches.
public bool Contains(NbtTag tag)
Parameters
tagNbtTagThe object to locate in this NbtCompound. May not be
null.
Returns
- bool
true if tag is found; otherwise, false.
Exceptions
- ArgumentNullException
tagisnull.
CopyTo(NbtTag[], int)
Copies the tags of the NbtCompound to an array, starting at a particular array index.
public void CopyTo(NbtTag[] array, int arrayIndex)
Parameters
arrayNbtTag[]The one-dimensional array that is the destination of the tag copied from NbtCompound. The array must have zero-based indexing.
arrayIndexintThe zero-based index in array at which copying begins.
Exceptions
- ArgumentNullException
arrayisnull.- ArgumentOutOfRangeException
arrayIndex is less than 0.
- ArgumentException
Given array is multidimensional; arrayIndex is equal to or greater than the length of array; the number of tags in this NbtCompound is greater than the available space from arrayIndex to the end of the destination array; or type NbtTag cannot be cast automatically to the type of the destination array.
Get(string)
Gets the tag with the specified name. May return null.
public NbtTag? Get(string tagName)
Parameters
tagNamestringThe name of the tag to get.
Returns
- NbtTag
The tag with the specified key. Null if tag with the given name was not found.
Exceptions
- ArgumentNullException
tagNameisnull.- InvalidCastException
If tag could not be cast to the desired tag.
GetEnumerator()
Returns an enumerator that iterates through all tags in this NbtCompound.
public IEnumerator<NbtTag> GetEnumerator()
Returns
- IEnumerator<NbtTag>
An IEnumerator>NbtTag< that can be used to iterate through the collection.
Get<T>(string)
Gets the tag with the specified name. May return null.
public T? Get<T>(string tagName) where T : NbtTag
Parameters
tagNamestringThe name of the tag to get.
Returns
- T
The tag with the specified key. Null if tag with the given name was not found.
Type Parameters
TType to cast the result to. Must derive from NbtTag.
Exceptions
- ArgumentNullException
tagNameisnull.- InvalidCastException
If tag could not be cast to the desired tag.
Remove(string)
Removes the tag with the specified name from this NbtCompound.
public bool Remove(string tagName)
Parameters
tagNamestringThe name of the tag to remove.
Returns
- bool
true if the tag is successfully found and removed; otherwise, false. This method returns false if name is not found in the NbtCompound.
Exceptions
- ArgumentNullException
tagNameisnull.
Remove(NbtTag)
Removes the first occurrence of a specific NbtTag from the NbtCompound. Looks for exact object matches, not name matches.
public bool Remove(NbtTag tag)
Parameters
tagNbtTagThe tag to remove from the NbtCompound.
Returns
- bool
true if tag was successfully removed from the NbtCompound; otherwise, false. This method also returns false if tag is not found.
Exceptions
- ArgumentNullException
tagisnull.- ArgumentException
If the given tag is unnamed
TryGet(string, out NbtTag?)
Gets the tag with the specified name.
public bool TryGet(string tagName, out NbtTag? result)
Parameters
tagNamestringThe name of the tag to get.
resultNbtTagWhen this method returns, contains the tag associated with the specified name, if the tag is found; otherwise, null. This parameter is passed uninitialized.
Returns
- bool
true if the NbtCompound contains a tag with the specified name; otherwise, false.
Exceptions
- ArgumentNullException
tagNameisnull.
TryGet<T>(string, out T?)
Gets the tag with the specified name.
public bool TryGet<T>(string tagName, out T? result) where T : NbtTag
Parameters
tagNamestringThe name of the tag to get.
resultTWhen this method returns, contains the tag associated with the specified name, if the tag is found; otherwise, null. This parameter is passed uninitialized.
Returns
- bool
true if the NbtCompound contains a tag with the specified name; otherwise, false.
Type Parameters
TType to cast the result to. Must derive from NbtTag.
Exceptions
- ArgumentNullException
tagNameisnull.- InvalidCastException
If tag could not be cast to the desired tag.