using System;
namespace Substrate.Nbt
{
///
/// A concrete representing a .
///
public sealed class SchemaNodeList : SchemaNode
{
private TagType _type;
private int _length;
private SchemaNode _subschema;
///
/// Gets the expected number of items contained in the corresponding .
///
public int Length
{
get { return _length; }
}
///
/// Gets the expected of the items contained in the corresponding .
///
public TagType Type
{
get { return _type; }
}
///
/// Gets a representing a schema that items contained in the corresponding should be verified against.
///
public SchemaNode SubSchema
{
get { return _subschema; }
}
///
/// Indicates whether there is an expected number of items of the corresponding .
///
public bool HasExpectedLength
{
get { return _length > 0; }
}
///
/// Constructs a new representing a named containing items of type .
///
/// The name of the corresponding .
/// The type of items contained in the corresponding .
public SchemaNodeList (string name, TagType type)
: base(name)
{
_type = type;
}
///
/// Constructs a new with additional options.
///
/// The name of the corresponding .
/// The type of items contained in the corresponding .
/// One or more option flags modifying the processing of this node.
public SchemaNodeList (string name, TagType type, SchemaOptions options)
: base(name, options)
{
_type = type;
}
///
/// Constructs a new representing a named containing items of type .
///
/// The name of the corresponding .
/// The type of items contained in the corresponding .
/// The number of items contained in the corresponding .
public SchemaNodeList (string name, TagType type, int length)
: base(name)
{
_type = type;
_length = length;
}
///
/// Constructs a new with additional options.
///
/// The name of the corresponding .
/// The type of items contained in the corresponding .
/// The number of items contained in the corresponding .
/// One or more option flags modifying the processing of this node.
public SchemaNodeList (string name, TagType type, int length, SchemaOptions options)
: base(name, options)
{
_type = type;
_length = length;
}
///
/// Constructs a new representing a named containing items of type matching the given schema.
///
/// The name of the corresponding .
/// The type of items contained in the corresponding .
/// A representing a schema to verify against items contained in the corresponding .
public SchemaNodeList (string name, TagType type, SchemaNode subschema)
: base(name)
{
_type = type;
_subschema = subschema;
}
///
/// Constructs a new with additional options.
///
/// The name of the corresponding .
/// The type of items contained in the corresponding .
/// A representing a schema to verify against items contained in the corresponding .
/// One or more option flags modifying the processing of this node.
public SchemaNodeList (string name, TagType type, SchemaNode subschema, SchemaOptions options)
: base(name, options)
{
_type = type;
_subschema = subschema;
}
///
/// Constructs a new representing a named containing items of type matching the given schema.
///
/// The name of the corresponding .
/// The type of items contained in the corresponding .
/// The number of items contained in the corresponding .
/// A representing a schema to verify against items contained in the corresponding .
public SchemaNodeList (string name, TagType type, int length, SchemaNode subschema)
: base(name)
{
_type = type;
_length = length;
_subschema = subschema;
}
///
/// Constructs a new with additional options.
///
/// The name of the corresponding .
/// The type of items contained in the corresponding .
/// The number of items contained in the corresponding .
/// A representing a schema to verify against items contained in the corresponding .
/// One or more option flags modifying the processing of this node.
public SchemaNodeList (string name, TagType type, int length, SchemaNode subschema, SchemaOptions options)
: base(name, options)
{
_type = type;
_length = length;
_subschema = subschema;
}
///
/// Constructs a default satisfying the constraints of this node.
///
/// A with a sensible default value. If a length is specified, default child objects of the necessary type will be created and added to the .
public override TagNode BuildDefaultTree ()
{
if (_length == 0) {
return new TagNodeList(_type);
}
TagNodeList list = new TagNodeList(_type);
for (int i = 0; i < _length; i++) {
list.Add(_subschema.BuildDefaultTree());
}
return list;
}
}
}