Table of Contents

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

tags IEnumerable<NbtTag>

Collection of tags to assign to this tag's Value. May not be null

Exceptions

ArgumentNullException

tags is null, or one of the tags is null.

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

tagName string

Name 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

tagName string

Name to assign to this tag. May be null.

tags IEnumerable<NbtTag>

Collection of tags to assign to this tag's Value. May not be null

Exceptions

ArgumentNullException

tags is null, or one of the tags is null.

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

other NbtCompound

An existing NbtCompound to copy. May not be null.

Exceptions

ArgumentNullException

other is null.

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

tagName string

The 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

tagName is null; or if trying to assign null value.

ArgumentException

tagName does 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

IEnumerable<string>

TagType

Type of this tag (Compound).

public override NbtTagType TagType { get; }

Property Value

NbtTagType

Tags

Gets a collection containing all tags in this NbtCompound.

public IEnumerable<NbtTag> Tags { get; }

Property Value

IEnumerable<NbtTag>

Methods

Add(NbtTag)

Adds a tag to this NbtCompound.

public void Add(NbtTag newTag)

Parameters

newTag NbtTag

The object to add to this NbtCompound.

Exceptions

ArgumentNullException

newTag is null.

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

newTags IEnumerable<NbtTag>

The collection whose elements should be added to this NbtCompound.

Exceptions

ArgumentNullException

newTags is null, or one of the tags in newTags is null.

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

tagName string

Tag name to search for. May not be null.

Returns

bool

true if a tag with given name was found; otherwise, false.

Exceptions

ArgumentNullException

tagName is null.

Contains(NbtTag)

Determines whether this NbtCompound contains a specific NbtTag. Looks for exact object matches, not name matches.

public bool Contains(NbtTag tag)

Parameters

tag NbtTag

The object to locate in this NbtCompound. May not be null.

Returns

bool

true if tag is found; otherwise, false.

Exceptions

ArgumentNullException

tag is null.

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

array NbtTag[]

The one-dimensional array that is the destination of the tag copied from NbtCompound. The array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

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

tagName string

The 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

tagName is null.

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

tagName string

The 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

T

Type to cast the result to. Must derive from NbtTag.

Exceptions

ArgumentNullException

tagName is null.

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

tagName string

The 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

tagName is null.

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

tag NbtTag

The 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

tag is null.

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

tagName string

The name of the tag to get.

result NbtTag

When 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

tagName is null.

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

tagName string

The name of the tag to get.

result T

When 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

T

Type to cast the result to. Must derive from NbtTag.

Exceptions

ArgumentNullException

tagName is null.

InvalidCastException

If tag could not be cast to the desired tag.