[DebuggerDisplay("{Topology}")] public sealed class Node : IBinary, ISml, IWriter, IReader, IEquatable<Node>
Nodes are the main organising entities in Grasshopper IO hierarchical dictionaries. Nodes may contain any number of uniquely named items, as well as any number of uniquely named child nodes. Nodes explicitly implement the IWriter and IReader interfaces, which is how nodes are most commonly exposed to client code.

Nodes are not thread-safe, not even for reading, since lookups and the inflation of serialised child nodes modify internal state.

Fields

IoVersionNumber

#
public const byte IoVersionNumber = 2
Represents the current IO version. When a breaking change to the data layout of GrasshopperIO archives must be implemented, this version will increment. I'm guessing 255 breaking changes will suffice for the lifetime of the Grasshopper 2 project, but if need be 255 can indicate a larger versioning integers stored subsequently.

IoVersionSpec

#
public static readonly DateTime IoVersionSpec
Defines when the current version specificiation was made official.

Properties

Explicit

IReader.Name

#
Name

ItemCount

#
public int ItemCount { get; }
Gets the number of items in this node.

Items

#
public IEnumerable<Item> Items { get; }
Iterate over all items in this node.

Name

#
public Name Name { get; }
Gets the location of this node.
Name

NodeCount

#
public int NodeCount { get; }
Gets the number of child nodes in this node.

Nodes

#
public IEnumerable<Node> Nodes { get; }
Iterate over all immediate child nodes.

Topology

#
public string Topology { get; }
Gets the structural description of this node. This includes all child nodes, but not any item names.

Methods

AddItem

#
public void AddItem(Item item)
Add a new item to this node. Item location must be unique.
item (Item)Item to add.
AddItem

AddItem

#
public void AddItem(Name name, Value value)
Add a new item to this node. Item location must be unique.
name (Name)Location of item to add.
value (Value)Item value.

AddNode

#
public void AddNode(Node node)
Add a duplicate of a node to this node.
node (Node)
AddNode

AddSerialisedNode

#
[EditorBrowsable(EditorBrowsableState.Never)] public void AddSerialisedNode(byte[] bytes)
Add a child node from its binary form, as produced by IO.WriteNodeToByteArray, without deserialising it. The child takes the name stored in the bytes. The bytes are written verbatim when this node is written in binary form, and must not contain file paths, which are made relative to the location being written to. This method allows for speedups in repeated serialisation of the same data.
bytes (byte[])Binary form of a node.

AllTypeIdentifiers

#
public HashSet<Guid> AllTypeIdentifiers()
Collect all the type identifiers associated with IStorable types which have been stored in this node, and all its children and grand-children.

AreIndentical

#
public static bool AreIndentical(Node a, Node b, EqualityLevel level, bool recursive)
Test two nodes for equality. This comparison tests both the location, children and items of the node.
a (Node)First node.
b (Node)Second node.
level (EqualityLevel)Identity strictness.
recursive (bool)If true, child nodes must also be identical.
True if nodes are identical.

Boolean

#
public bool Boolean(Name name)
name (Name)
Boolean

Boolean

#
public void Boolean(Name name, bool value)
name (Name)
value (bool)
Boolean

BooleanArray

#
public bool[] BooleanArray(Name name)
name (Name)
BooleanArray

BooleanArray

#
public void BooleanArray(Name name, bool[] value)
name (Name)
value (bool[])
BooleanArray

Clear

#
public void Clear()
Clear this node by removing all children and items.

Complex128

#
public Complex Complex128(Name name)
name (Name)
Complex128

Complex128

#
public void Complex128(Name name, Complex value)
name (Name)
value (Complex)
Complex128

Create

#
public static Node Create()
Create a loose, empty node.

Create

#
public static Node Create(Name name, IStorable content)
Create a loose node which contains a single storable object.
name (Name)Name of this root node.
content (IStorable)Data to store in this node.

Create

#
public static Node Create(Name name)
Create a loose, empty node.
name (Name)Name of this root node.

DateTime

#
public DateTime DateTime(Name name)
name (Name)
DateTime

DateTime

#
public void DateTime(Name name, DateTime value)
name (Name)
value (DateTime)
DateTime

Decimal128

#
public decimal Decimal128(Name name)
name (Name)
Decimal128

Decimal128

#
public void Decimal128(Name name, decimal value)
name (Name)
value (decimal)
Decimal128

EmitNode

#
public Node EmitNode(Name name)
Add a new child to this node. The node name+index may not collide with another child already part of this node.
name (Name)Name of node to emit.

EnumerateAndExecute

#
public void EnumerateAndExecute(object incomingToken = null, NodeMethod nodeMethod = null, ItemMethod itemMethod = null)
Enumerate over all child nodes and items in this node and invoke a delegate for each.
incomingToken (object = null)Token to use for first level invokes.
nodeMethod (NodeMethod = null)Method for handling all nodes.
itemMethod (ItemMethod = null)Method for handling all items.

Equals

#
public bool Equals(Node other)
other (Node)

Equals

#
public override bool Equals(object obj)
obj (object)
Object.Equals

FilePath

#
public AbsRelPaths FilePath(Name name)
name (Name)
FilePath

FilePath

#
public void FilePath(Name name, AbsRelPaths value)
name (Name)
value (AbsRelPaths)
FilePath

FilePath

#
public void FilePath(Name name, FileSystemPath absolutePath)
name (Name)
absolutePath (FileSystemPath)
FilePath

FindChildren

#
public IEnumerable<Node> FindChildren(Name name)
Find all children with matching names. This includes immediate children, grand-children etc. Results are returned in a breadth-first manner.
name (Name)

FindChildren

#
public IEnumerable<Node> FindChildren(Predicate<Name> predicate)
Find all children whose name matches a predicate. This includes immediate children, grand-children etc. Results are returned in a breadth-first manner.
predicate (Predicate<Name>)

FindDifferences

#
public static Differences FindDifferences(Node a, Node b, EqualityLevel level, params NodeMatcher[] matchers)
Find the differences between two nodes.
a (Node)First node.
b (Node)Second node.
level (EqualityLevel)Level of comparison for differences.
matchers (params NodeMatcher[])Matchers to apply.

FindItem

#
public Value FindItem(Name name)
Get the value associated with the specified location.
name (Name)Location of value to find.
The value linked to the given name and index or null if no such value exists.
FindItem

FindNode

#
public Node FindNode(Name name)
Get the child with the specified name and index.
name (Name)Name of node to retrieve.
The node with the given name and index or null if no such node exists.

FindParents

#
public IEnumerable<Node> FindParents(Name name)
Find all parents with matching names. The nearest parent is returned first.
name (Name)

FindParents

#
public IEnumerable<Node> FindParents(Predicate<Name> predicate)
Find all parents whose name matches a predicate. The nearest parent is returned first.
predicate (Predicate<Name>)

GetHashCode

#
public override int GetHashCode()
Gets the hash code for this node. Note that nodes are mutable and that this method is *not* threadsafe. You should never rely on node hashes if you suspect some thread other than the caller may be affecting this node or any of the child nodes. Also note that the hash does not include any of the messaging strings.
Explicit

IBinary.Read

#
void IBinary.Read(BinaryReader reader, ReadContext context)
Explicit implementation of ISerializable.Read. Use the static methods on the IO class to deserialize nodes correctly and with a minimum of effort.
reader (BinaryReader)
context (ReadContext)
Read
Explicit

IBinary.Write

#
void IBinary.Write(BinaryWriter writer, WriteContext context)
Explicit implementation of IBinary.Write(BinaryWriter, WriteContext). Use the static methods on the IO class to serialize nodes correctly and with a minimum of effort.
writer (BinaryWriter)
context (WriteContext)
Write
Explicit

ISml.Write

#
void ISml.Write(SmlWriter writer, WriteContext context)
Explicit implementation of IBinary.Write(BinaryWriter, WriteContext). Use the static methods on the IO class to serialize nodes correctly and with a minimum of effort.
writer (SmlWriter)
context (WriteContext)
Write
Explicit

IReader.FindReader

#
IReader IReader.FindReader(Name name)
name (Name)
FindReader
Explicit

IReader.GenericArray<T>

#
T[] IReader.GenericArray<T>(Name name)
name (Name)
GenericArray
Explicit

IReader.SupportsArray<T>

#
bool IReader.SupportsArray<T>()
SupportsArray
Explicit

IReader.TryRead<T>

#
T IReader.TryRead<T>(Name name, T valueIfMissing)
name (Name)
valueIfMissing (T)
TryRead
Explicit

IWriter.CreateWriter

#
IWriter IWriter.CreateWriter(Name name)
name (Name)
CreateWriter
Explicit

IWriter.GenericArray<T>

#
void IWriter.GenericArray<T>(Name name, T[] array)
name (Name)
array (T[])
GenericArray
Explicit

IWriter.SupportsArray<T>

#
bool IWriter.SupportsArray<T>()
SupportsArray

Guid128

#
public Guid Guid128(Name name)
name (Name)
Guid128

Guid128

#
public void Guid128(Name name, Guid value)
name (Name)
value (Guid)
Guid128

GuidArray

#
public Guid[] GuidArray(Name name)
name (Name)
GuidArray

GuidArray

#
public void GuidArray(Name name, Guid[] value)
name (Name)
value (Guid[])
GuidArray

HasItem

#
public bool HasItem(Name name, DataType storageType)
Test to see whether an item with a specific name and index has been defined in this node.
name (Name)Location of item to find.
storageType (DataType)Item data type.
True when an item with this name and index exists.
HasItem

HasItem

#
public bool HasItem(Name name)
Test to see whether an item with a specific name and index has been defined in this node.
name (Name)Location of item to find.
True when an item with this name and index exists.
HasItem

HasItemOrNode

#
public bool HasItemOrNode(Name name)
Gets whether the specified location is available as either an item or a node.
name (Name)
HasItemOrNode

HasNode

#
public bool HasNode(Name name)
Test to see whether a child with a specific name and index has been defined in this node.
name (Name)
True when a child with this name and index exists.
HasNode

Integer32

#
public int Integer32(Name name)
name (Name)
Integer32

Integer32

#
public void Integer32(Name name, int value)
name (Name)
value (int)
Integer32

Integer32Array

#
public int[] Integer32Array(Name name)
name (Name)
Integer32Array

Integer32Array

#
public void Integer32Array(Name name, int[] value)
name (Name)
value (int[])
Integer32Array

Integer64

#
public long Integer64(Name name)
name (Name)
Integer64

Integer64

#
public void Integer64(Name name, long value)
name (Name)
value (long)
Integer64

Integer64Array

#
public long[] Integer64Array(Name name)
name (Name)
Integer64Array

Integer64Array

#
public void Integer64Array(Name name, params long[] value)
name (Name)
value (params long[])
Integer64Array

Integer8

#
public byte Integer8(Name name)
name (Name)
Integer8

Integer8

#
public void Integer8(Name name, byte value)
name (Name)
value (byte)
Integer8

Integer8Array

#
public byte[] Integer8Array(Name name)
name (Name)
Integer8Array

Integer8Array

#
public void Integer8Array(Name name, byte[] value)
name (Name)
value (byte[])
Integer8Array

IntegerXx

#
public BigInteger IntegerXx(Name name)
name (Name)
IntegerXx

IntegerXx

#
public void IntegerXx(Name name, BigInteger value)
name (Name)
value (BigInteger)
IntegerXx

Number32

#
public float Number32(Name name)
name (Name)
Number32

Number32

#
public void Number32(Name name, float value)
name (Name)
value (float)
Number32

Number32Array

#
public float[] Number32Array(Name name)
name (Name)
Number32Array

Number32Array

#
public void Number32Array(Name name, float[] value)
name (Name)
value (float[])
Number32Array

Number64

#
public double Number64(Name name)
name (Name)
Number64

Number64

#
public void Number64(Name name, double value)
name (Name)
value (double)
Number64

Number64Array

#
public double[] Number64Array(Name name)
name (Name)
Number64Array

Number64Array

#
public void Number64Array(Name name, double[] value)
name (Name)
value (double[])
Number64Array

RemoveItem

#
public void RemoveItem(Name name)
Remove an item from this node.
name (Name)Location of item to remove.

RemoveNode

#
public void RemoveNode(Name name)
Remove a child from this node.
name (Name)Location of node to remove.

ReplaceItem

#
public void ReplaceItem(Item item)
Replace an existing item, or add it if it doesn't exist yet.
item (Item)New item value.

Select

#
public Node Select(string path)
Try and find a node in this hierarchy.
path (string)Path to child or grand-child. Must be a comma separated list of names.
Child node if found, otherwise null.

Storable

#
public IStorable Storable(Name name)
name (Name)
Storable

Storable<T>

#
public T Storable<T>(Name name)
name (Name)
Storable

Storable

#
public void Storable(Name name, IStorable value)
name (Name)
value (IStorable)
Storable

StorableArray<T>

#
public T[] StorableArray<T>(Name name)
name (Name)
StorableArray

StorableArray<T>

#
public void StorableArray<T>(Name name, IEnumerable<T> storableValues)
name (Name)
storableValues (IEnumerable<T>)
StorableArray

String

#
public string String(Name name)
name (Name)
String

String

#
public void String(Name name, string value)
name (Name)
value (string)
String

StringArray

#
public string[] StringArray(Name name)
name (Name)
StringArray

StringArray

#
public void StringArray(Name name, string[] value)
name (Name)
value (string[])
StringArray

TimeSpan

#
public TimeSpan TimeSpan(Name name)
name (Name)
TimeSpan

TimeSpan

#
public void TimeSpan(Name name, TimeSpan value)
name (Name)
value (TimeSpan)
TimeSpan

ToString

#
public override string ToString()
Returns a string that represents the current object.
A string that represents the current object.
Object.ToString

TryFindChild

#
public Node TryFindChild(params Name[] path)
Try and find the child node which is reached via the given path.
path (params Name[])

TryFindParent

#
public Node TryFindParent(params Name[] path)
Try and find the parent node which is reached via the given path.
path (params Name[])

Type

#
public Type Type(Name name, IEnumerable<Type> fallbackList, out Type fallback)
name (Name)
fallbackList (IEnumerable<Type>)
fallback (out Type)
Type

Type

#
public Type Type(Name name)
name (Name)
Type

Type

#
public void Type(Name name, Type value)
name (Name)
value (Type)
Type

TypeName

#
public string TypeName(Name name)
name (Name)
TypeName

Version

#
public Version Version(Name name)
name (Name)
Version

Version

#
public void Version(Name name, Version value)
name (Name)
value (Version)
Version