IO

public static class IO
Static methods for safe reading and writing to and from IStorable implementations.

Methods

Duplicate

#
public static IStorable Duplicate(IStorable instance)
Duplicate an instance of an IStorable type using (de)serialization.
instance (IStorable)Instance to duplicate.
Duplicated instance.

Duplicate<T>

#
public static T Duplicate<T>(T instance)
Duplicate an instance of an IStorable type using (de)serialization.
instance (T)Instance to duplicate.
Duplicated instance.

GetIoId

#Example
public static Guid GetIoId(this Type type, bool inherit = false)
Gets the value of the identifier attribute associated with a type. If the type doesn't have the IdentifierAttribute, an exception will be thrown.
type (Type)Type to inspect.
inherit (bool = false)True to search this types inheritance chain to find the attribute.
Identifier.

GetIStorableConstructor

#
public static bool GetIStorableConstructor(Type type, out ConstructorInfo constructor)
Gets the constructor of a type which takes a single IReader argument. If such a constructor does not exist null will be returned.
type (Type)
constructor (out ConstructorInfo)

IsObsolete

#Example
public static bool IsObsolete(this Type type, out string workAround)
Gets the value of the identifier attribute associated with a type. If the type doesn't have the IdentifierAttribute, an exception will be thrown.
type (Type)Type to inspect.
workAround (out string)If the type is obsolete, returns the work around message here.
Identifier.

ReadNodeFromByteArray

#
public static IReader ReadNodeFromByteArray(byte[] array, string pathHint)
Read a node directly from a byte array.
array (byte[])
pathHint (string)

ReadNodeFromFile

#
public static IReader ReadNodeFromFile(string path)
Read a node from a file.
path (string)File path.
Deserialized node.

ReadNodeFromStream

#
public static IReader ReadNodeFromStream(BinaryReader reader, ReadContext context)
Read a node from a binary reader.
reader (BinaryReader)Binary reader.
context (ReadContext)Deserialisation context.
Deserialized node.

ReadNodeFromStream

#
public static IReader ReadNodeFromStream(Stream stream, ReadContext context)
Read a node from a stream.
stream (Stream)Data stream.
context (ReadContext)Deserialisation context.
Deserialized node.

ReadStorableFromByteArray<T>

#
public static T ReadStorableFromByteArray<T>(byte[] bytes, Name name = null)
Deserialise a byte array into an IStorable instance.
bytes (byte[])Byte array to read.
name (Name = null)Name under which the data is stored. If omitted, "X" is assumed.

ReadStorableFromFile

#
public static IStorable ReadStorableFromFile(string path)
Read an IStorable object from a file.
path (string)File.
Deserialised object.

ReadStorableFromFile<T>

#
public static T ReadStorableFromFile<T>(string path)
Read an IStorable object from a file.
path (string)File.
Deserialised object.

ReadStorableFromStream

#
public static IStorable ReadStorableFromStream(BinaryReader reader, ReadContext context)
Read an IStorable object from a binary reader.
reader (BinaryReader)Binary reader.
context (ReadContext)Deserialisation context.
Deserialised object.

ReadStorableFromStream

#
public static IStorable ReadStorableFromStream(Stream stream, ReadContext context)
Read an IStorable object from a stream.
stream (Stream)Data stream.
context (ReadContext)Deserialisation context.
Deserialised object.

ReadStorableFromStream<T>

#
public static T ReadStorableFromStream<T>(BinaryReader reader, ReadContext context)
Read an IStorable object from a binary reader.
reader (BinaryReader)Binary reader.
context (ReadContext)Deserialisation context.
Deserialised object.

ReadStorableFromStream<T>

#
public static T ReadStorableFromStream<T>(Stream stream, ReadContext context)
Read an IStorable object from a stream.
stream (Stream)Data stream.
context (ReadContext)Deserialisation context.
Deserialised object.

RegisterRestorableType

#
public static bool RegisterRestorableType(Type type, Guid id)
Add a type to the known set of restorable types. Consider using the overload which only takes a single type parameter to ensure your registration is correct.
type (Type)Type to add.
id (Guid)Identifier associated with type.
True if registration was successful.

RegisterRestorableType

#
public static bool RegisterRestorableType(Type type)
Add a type to the known set of restorable types. The type must have an IoIdAttribute attribute associated with it.
type (Type)Type to add.
True if registration was successful.

ResolveType

#
public static Type ResolveType(Guid identifier)
Try and get the type associated with a particular identifier.
identifier (Guid)

TryGetIoId

#Example
public static bool TryGetIoId(this Type type, out Guid id, bool inherit = false)
Gets the value of the IoId attribute associated with a type.
type (Type)Type to inspect.
id (out Guid)Returned identifier.
inherit (bool = false)True to search this types inheritance chain to find the attribute.
True if an identifier was found.

ValidateIStorable

#
public static bool ValidateIStorable(Type type, out ConstructorInfo constructor, out string reason)
Validate the design of a type which implements the IStorable interface.
type (Type)Type of IStorable.
constructor (out ConstructorInfo)The restoration constructor will be returned here.
reason (out string)If this method returns false, the reason for the invalid type.
True if instance is valid.

ValidateIStorable

#
public static bool ValidateIStorable(Type type, out string reason)
Validate the design of a type which implements the IStorable interface.
type (Type)Type of IStorable.
reason (out string)If this method returns false, the reason for the invalid type.
True if instance is valid.

WriteNodeToByteArray

#
public static byte[] WriteNodeToByteArray(IWriter node, string pathHint)
Serialize a node directly to a byte array.
node (IWriter)Node to serialise.
pathHint (string)Location of result, if known or makes sense.

WriteNodeToFile

#
public static void WriteNodeToFile(IWriter node, string path)
Write a node to a file.
node (IWriter)Node to serialize.
path (string)File path to write to.

WriteNodeToStream

#
public static void WriteNodeToStream(IWriter node, BinaryWriter writer, WriteContext context)
Append a node to a stream using a binary writer.
node (IWriter)Node to serialize.
writer (BinaryWriter)Binary writer.
context (WriteContext)Serialisation context.

WriteNodeToStream

#
public static void WriteNodeToStream(IWriter node, Stream stream, WriteContext context)
Append a node to a stream.
node (IWriter)Node to serialize.
stream (Stream)Stream to write to.
context (WriteContext)Deserialisation context.

WriteStorableToByteArray

#
public static byte[] WriteStorableToByteArray(IStorable value, Name name = null)
Serialise an IStorable instance to a byte array.
value (IStorable)IStorable to serialise.
name (Name = null)Name under which to store the data. If omitted, "X" is used.

WriteStorableToFile

#
public static void WriteStorableToFile(IStorable storable, string path)
Write a storable object to a file.
storable (IStorable)Storable object.
path (string)File destination.

WriteStorableToStream

#
public static void WriteStorableToStream(IStorable storable, BinaryWriter writer, WriteContext context)
Append a storable object to a stream.
storable (IStorable)Storable object.
writer (BinaryWriter)Writer to use.
context (WriteContext)Serialisation context.

WriteStorableToStream

#
public static void WriteStorableToStream(IStorable storable, Stream stream, WriteContext context)
Append a storable object to a stream.
storable (IStorable)Storable object.
stream (Stream)File stream to write to.
context (WriteContext)Serialisation context.

Events

LinkType

#
public static event EventHandler<LinkTypeEventArgs> LinkType
This event is raised whenever a specific type implementation is required during deserialisation. Normally, all deserialisable types will have been registered with GrasshopperIO.IO ahead of time, but it is possible some types were omitted from standard registration due to their non-publicness, or maybe because they need to be loaded on demand.