Table of Contents

Class NbtList

Namespace
fNbt
Assembly
fNbt.dll

A tag containing a list of unnamed tags, all of the same kind.

public sealed class NbtList : NbtTag, ICloneable, IList<NbtTag>, ICollection<NbtTag>, IEnumerable<NbtTag>, IList, ICollection, IEnumerable
Inheritance
NbtList
Implements
Inherited Members

Constructors

NbtList()

Creates an unnamed NbtList with empty contents and undefined ListType.

public NbtList()

NbtList(IEnumerable<NbtTag>)

Creates an unnamed NbtList with the given contents, and inferred ListType. If given tag array is empty, NbtTagType remains Unknown.

public NbtList(IEnumerable<NbtTag> tags)

Parameters

tags IEnumerable<NbtTag>

Collection of tags to insert into the list. All tags are expected to be of the same type. ListType is inferred from the first tag. List may be empty, but may not be null.

Exceptions

ArgumentNullException

tags is null.

ArgumentException

If given tags are of mixed types.

NbtList(IEnumerable<NbtTag>, NbtTagType)

Creates an unnamed NbtList with the given contents, and an explicitly specified ListType.

public NbtList(IEnumerable<NbtTag> tags, NbtTagType givenListType)

Parameters

tags IEnumerable<NbtTag>

Collection of tags to insert into the list. All tags are expected to be of the same type (matching givenListType). List may be empty, but may not be null.

givenListType NbtTagType

Name to assign to this tag. May be Unknown (to infer type from the first element of tags).

Exceptions

ArgumentNullException

tags is null.

ArgumentOutOfRangeException

givenListType is not a valid tag type.

ArgumentException

If given tags do not match givenListType, or are of mixed types.

NbtList(string?)

Creates an NbtList with given name, empty contents, and undefined ListType.

public NbtList(string? tagName)

Parameters

tagName string

Name to assign to this tag. May be null.

NbtList(string?, IEnumerable<NbtTag>)

Creates an NbtList with the given name and contents, and inferred ListType. If given tag array is empty, NbtTagType remains Unknown.

public NbtList(string? tagName, IEnumerable<NbtTag> tags)

Parameters

tagName string

Name to assign to this tag. May be null.

tags IEnumerable<NbtTag>

Collection of tags to insert into the list. All tags are expected to be of the same type. ListType is inferred from the first tag. List may be empty, but may not be null.

Exceptions

ArgumentNullException

tags is null.

ArgumentException

If given tags are of mixed types.

NbtList(string?, IEnumerable<NbtTag>?, NbtTagType)

Creates an NbtList with the given name and contents, and an explicitly specified ListType.

public NbtList(string? tagName, IEnumerable<NbtTag>? tags, NbtTagType givenListType)

Parameters

tagName string

Name to assign to this tag. May be null.

tags IEnumerable<NbtTag>

Collection of tags to insert into the list. All tags are expected to be of the same type (matching givenListType). May be empty or null.

givenListType NbtTagType

Name to assign to this tag. May be Unknown (to infer type from the first element of tags).

Exceptions

ArgumentOutOfRangeException

givenListType is not a valid tag type.

ArgumentException

If given tags do not match givenListType, or are of mixed types.

NbtList(string?, NbtTagType)

Creates an NbtList with the given name, empty contents, and an explicitly specified ListType.

public NbtList(string? tagName, NbtTagType givenListType)

Parameters

tagName string

Name to assign to this tag. May be null.

givenListType NbtTagType

Name to assign to this tag. If givenListType is Unknown, ListType will be inferred from the first tag added to this NbtList.

Exceptions

ArgumentOutOfRangeException

givenListType is not a valid tag type.

NbtList(NbtList)

Creates a deep copy of given NbtList.

public NbtList(NbtList other)

Parameters

other NbtList

An existing NbtList to copy. May not be null.

Exceptions

ArgumentNullException

other is null.

NbtList(NbtTagType)

Creates an unnamed NbtList with empty contents and an explicitly specified ListType. If ListType is Unknown, it will be inferred from the type of the first added tag. Otherwise, all tags added to this list are expected to be of the given type.

public NbtList(NbtTagType givenListType)

Parameters

givenListType NbtTagType

Name to assign to this tag. May be Unknown.

Exceptions

ArgumentOutOfRangeException

givenListType is not a recognized tag type.

Properties

Count

Gets the number of tags contained in the NbtList.

public int Count { get; }

Property Value

int

The number of tags contained in the NbtList.

this[int]

Gets or sets the tag at the specified index.

public override NbtTag this[int tagIndex] { get; set; }

Parameters

tagIndex int

The zero-based index of the tag to get or set.

Property Value

NbtTag

The tag at the specified index.

Exceptions

ArgumentOutOfRangeException

tagIndex is not a valid index in the NbtList.

ArgumentNullException

value is null.

ArgumentException

Given tag's type does not match ListType.

ListType

Gets or sets the tag type of this list. All tags in this NbtTag must be of the same type.

public NbtTagType ListType { get; set; }

Property Value

NbtTagType

Exceptions

ArgumentException

If the given NbtTagType does not match the type of existing list items (for non-empty lists).

ArgumentOutOfRangeException

If the given NbtTagType is a recognized tag type.

TagType

Type of this tag (List).

public override NbtTagType TagType { get; }

Property Value

NbtTagType

Methods

Add(NbtTag)

Adds a tag to this NbtList.

public void Add(NbtTag newTag)

Parameters

newTag NbtTag

The tag to add to this NbtList.

Exceptions

ArgumentNullException

newTag is null.

ArgumentException

If newTag does not match ListType.

AddRange(IEnumerable<NbtTag>)

Adds all tags from the specified collection to the end of this NbtList.

public void AddRange(IEnumerable<NbtTag> newTags)

Parameters

newTags IEnumerable<NbtTag>

The collection whose elements should be added to this NbtList.

Exceptions

ArgumentNullException

newTags is null.

ArgumentException

If given tags do not match ListType, or are of mixed types.

Clear()

Removes all tags from this NbtList.

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(NbtTag)

Determines whether this NbtList contains a specific tag.

public bool Contains(NbtTag item)

Parameters

item NbtTag

The tag to locate in this NbtList.

Returns

bool

true if given tag is found in this NbtList; otherwise, false.

CopyTo(NbtTag[], int)

Copies the tags of this NbtList 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 NbtList. 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 NbtList 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.

GetEnumerator()

Returns an enumerator that iterates through all tags in this NbtList.

public IEnumerator<NbtTag> GetEnumerator()

Returns

IEnumerator<NbtTag>

An IEnumerator>NbtTag< that can be used to iterate through the list.

Get<T>(int)

Gets or sets the tag with the specified name.

public T Get<T>(int tagIndex) where T : NbtTag

Parameters

tagIndex int

The zero-based index of the tag to get or set.

Returns

T

The tag with the specified key.

Type Parameters

T

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

Exceptions

ArgumentOutOfRangeException

tagIndex is not a valid index in the NbtList.

InvalidCastException

If tag could not be cast to the desired tag.

IndexOf(NbtTag?)

Determines the index of a specific tag in this NbtList

public int IndexOf(NbtTag? tag)

Parameters

tag NbtTag

The tag to locate in this NbtList.

Returns

int

The index of tag if found in the list; otherwise, -1.

Insert(int, NbtTag)

Inserts an item to this NbtList at the specified index.

public void Insert(int tagIndex, NbtTag newTag)

Parameters

tagIndex int

The zero-based index at which newTag should be inserted.

newTag NbtTag

The tag to insert into this NbtList.

Exceptions

ArgumentOutOfRangeException

tagIndex is not a valid index in this NbtList.

ArgumentNullException

newTag 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 this NbtList.

Returns

bool

true if tag was successfully removed from this NbtList; otherwise, false. This method also returns false if tag is not found.

Exceptions

ArgumentNullException

tag is null.

RemoveAt(int)

Removes a tag at the specified index from this NbtList.

public void RemoveAt(int index)

Parameters

index int

The zero-based index of the item to remove.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the NbtList.

ToArray()

Copies all tags in this NbtList to an array.

public NbtTag[] ToArray()

Returns

NbtTag[]

Array of NbtTags.

ToArray<T>()

Copies all tags in this NbtList to an array, and casts it to the desired type.

public T[] ToArray<T>() where T : NbtTag

Returns

T[]

Array of NbtTags cast to the desired type.

Type Parameters

T

Type to cast every member of NbtList to. Must derive from NbtTag.

Exceptions

InvalidCastException

If contents of this list cannot be cast to the given type.