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
tagsIEnumerable<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
tagsisnull.- 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
tagsIEnumerable<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.givenListTypeNbtTagTypeName to assign to this tag. May be Unknown (to infer type from the first element of tags).
Exceptions
- ArgumentNullException
tagsisnull.- ArgumentOutOfRangeException
givenListTypeis 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
tagNamestringName 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
tagNamestringName to assign to this tag. May be
null.tagsIEnumerable<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
tagsisnull.- 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
tagNamestringName to assign to this tag. May be
null.tagsIEnumerable<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.givenListTypeNbtTagTypeName to assign to this tag. May be Unknown (to infer type from the first element of tags).
Exceptions
- ArgumentOutOfRangeException
givenListTypeis 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
tagNamestringName to assign to this tag. May be
null.givenListTypeNbtTagTypeName to assign to this tag. If givenListType is Unknown, ListType will be inferred from the first tag added to this NbtList.
Exceptions
- ArgumentOutOfRangeException
givenListTypeis not a valid tag type.
NbtList(NbtList)
Creates a deep copy of given NbtList.
public NbtList(NbtList other)
Parameters
otherNbtListAn existing NbtList to copy. May not be
null.
Exceptions
- ArgumentNullException
otherisnull.
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
givenListTypeNbtTagTypeName to assign to this tag. May be Unknown.
Exceptions
- ArgumentOutOfRangeException
givenListTypeis 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
tagIndexintThe zero-based index of the tag to get or set.
Property Value
- NbtTag
The tag at the specified index.
Exceptions
- ArgumentOutOfRangeException
tagIndexis not a valid index in the NbtList.- ArgumentNullException
valueisnull.- 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
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
Methods
Add(NbtTag)
Adds a tag to this NbtList.
public void Add(NbtTag newTag)
Parameters
newTagNbtTagThe tag to add to this NbtList.
Exceptions
- ArgumentNullException
newTagisnull.- ArgumentException
If
newTagdoes 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
newTagsIEnumerable<NbtTag>The collection whose elements should be added to this NbtList.
Exceptions
- ArgumentNullException
newTagsisnull.- 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
itemNbtTagThe 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
arrayNbtTag[]The one-dimensional array that is the destination of the tag copied from NbtList. 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 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
tagIndexintThe zero-based index of the tag to get or set.
Returns
- T
The tag with the specified key.
Type Parameters
TType to cast the result to. Must derive from NbtTag.
Exceptions
- ArgumentOutOfRangeException
tagIndexis 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
tagNbtTagThe 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
tagIndexintThe zero-based index at which newTag should be inserted.
newTagNbtTagThe tag to insert into this NbtList.
Exceptions
- ArgumentOutOfRangeException
tagIndexis not a valid index in this NbtList.- ArgumentNullException
newTagisnull.
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 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
tagisnull.
RemoveAt(int)
Removes a tag at the specified index from this NbtList.
public void RemoveAt(int index)
Parameters
indexintThe zero-based index of the item to remove.
Exceptions
- ArgumentOutOfRangeException
indexis 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
TType 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.