CompoundStorageBuilder Class
Definition
- Assembly
- Bodu.IO.Compound.dll
- Package
- Bodu.IO.Compound 1.0.0
Represents a storage entry in a mutable compound-file object model - a named container of child storages and streams.
public sealed class CompoundStorageBuilder : CompoundEntryBuilder, IDictionary<string, CompoundEntryBuilder>, ICollection<KeyValuePair<string, CompoundEntryBuilder>>, IEnumerable<KeyValuePair<string, CompoundEntryBuilder>>, IEnumerable
- Inheritance
-
CompoundStorageBuilder
- Implements
- Inherited Members
- Extension Methods
Remarks
This is the authoring counterpart of CompoundStorage and the compound-file analogue of a
JsonObject: children are keyed by name and a node belongs to at most one storage at a time. A storage with no
parent is the root of a document; serialize a tree with its ToArray(CompoundBuildOptions) /
WriteTo(Stream, CompoundBuildOptions) members.
Names are compared per CompoundStorageBuilderOptions (case-insensitive by default, matching the compound-file format). The serialization order of children is determined by the builder, not by insertion order.
Constructors
CompoundStorageBuilder()
Initializes a new instance of the CompoundStorageBuilder class with default options.
public CompoundStorageBuilder()
CompoundStorageBuilder(CompoundStorageBuilderOptions)
Initializes a new instance of the CompoundStorageBuilder class with the specified options.
public CompoundStorageBuilder(CompoundStorageBuilderOptions options)
Parameters
optionsCompoundStorageBuilderOptionsThe options controlling name comparison.
Properties
Count
Gets the number of elements contained in the ICollection<T>.
public int Count { get; }
Property Value
- int
The number of elements contained in the ICollection<T>.
EntryType
Gets the kind of entry this node represents.
public override CompoundEntryType EntryType { get; }
Property Value
- CompoundEntryType
The CompoundEntryType of the node.
this[string]
Gets or sets the element with the specified key.
public CompoundEntryBuilder this[string key] { get; set; }
Parameters
keystringThe key of the element to get or set.
Property Value
- CompoundEntryBuilder
The element with the specified key.
Exceptions
- ArgumentNullException
keyis null.- KeyNotFoundException
The property is retrieved and
keyis not found.- NotSupportedException
The property is set and the IDictionary<TKey, TValue> is read-only.
- ArgumentNullException
Thrown when the key or value is null.
- CompoundFileSerializationException
Thrown when the name is invalid.
Keys
Gets an ICollection<T> containing the keys of the IDictionary<TKey, TValue>.
public ICollection<string> Keys { get; }
Property Value
- ICollection<string>
An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.
Values
Gets an ICollection<T> containing the values in the IDictionary<TKey, TValue>.
public ICollection<CompoundEntryBuilder> Values { get; }
Property Value
- ICollection<CompoundEntryBuilder>
An ICollection<T> containing the values in the object that implements IDictionary<TKey, TValue>.
Methods
Add(string, CompoundEntryBuilder)
Adds an element with the provided key and value to the IDictionary<TKey, TValue>.
public void Add(string key, CompoundEntryBuilder value)
Parameters
keystringThe object to use as the key of the element to add.
valueCompoundEntryBuilderThe object to use as the value of the element to add.
Exceptions
- ArgumentNullException
keyis null.- ArgumentException
An element with the same key already exists in the IDictionary<TKey, TValue>.
- NotSupportedException
The IDictionary<TKey, TValue> is read-only.
- CompoundFileSerializationException
Thrown when the name is invalid or already present.
AddStorage(string)
Adds a new child storage with the specified name.
public CompoundStorageBuilder AddStorage(string name)
Parameters
namestringThe storage name.
Returns
- CompoundStorageBuilder
The created CompoundStorageBuilder.
Exceptions
- CompoundFileSerializationException
Thrown when the name is invalid or already present.
AddStream(string, Func<Stream>, long)
Adds a new deferred child stream whose payload is read on demand from a re-openable source.
public CompoundStreamBuilder AddStream(string name, Func<Stream> openRead, long length)
Parameters
namestringThe stream name.
openReadFunc<Stream>A factory that opens a readable stream over the payload each time it is invoked.
lengthlongThe payload length, in bytes.
Returns
- CompoundStreamBuilder
The created CompoundStreamBuilder.
Exceptions
- CompoundFileSerializationException
Thrown when the name is invalid or already present.
AddStream(string, ReadOnlyMemory<byte>)
Adds a new child stream with the specified name and payload.
public CompoundStreamBuilder AddStream(string name, ReadOnlyMemory<byte> content)
Parameters
namestringThe stream name.
contentReadOnlyMemory<byte>The payload bytes.
Returns
- CompoundStreamBuilder
The created CompoundStreamBuilder.
Exceptions
- CompoundFileSerializationException
Thrown when the name is invalid or already present.
AddStreamFromFile(string, string)
Adds a new deferred child stream whose payload is read on demand from a file.
public CompoundStreamBuilder AddStreamFromFile(string name, string path)
Parameters
Returns
- CompoundStreamBuilder
The created CompoundStreamBuilder.
Exceptions
- CompoundFileSerializationException
Thrown when the name is invalid or already present.
Clear()
Removes all items from the ICollection<T>.
public void Clear()
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
ContainsKey(string)
Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.
public bool ContainsKey(string key)
Parameters
keystringThe key to locate in the IDictionary<TKey, TValue>.
Returns
- bool
true if the IDictionary<TKey, TValue> contains an element with the key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
ContainsName(string)
Determines whether the storage contains a child with the specified name.
public bool ContainsName(string name)
Parameters
namestringThe name to look up.
Returns
CreateRoot()
Creates a new, detached root storage node named Root Entry.
public static CompoundStorageBuilder CreateRoot()
Returns
- CompoundStorageBuilder
A root CompoundStorageBuilder ready for authoring.
CreateRoot(CompoundStorageBuilderOptions)
Creates a new, detached root storage node with the specified options.
public static CompoundStorageBuilder CreateRoot(CompoundStorageBuilderOptions options)
Parameters
optionsCompoundStorageBuilderOptionsThe options controlling name comparison.
Returns
- CompoundStorageBuilder
A root CompoundStorageBuilder ready for authoring.
DeepClone()
Creates a deep, detached copy of this node and its descendants.
public override CompoundEntryBuilder DeepClone()
Returns
- CompoundEntryBuilder
An independent copy with no parent.
EnumerateStorages()
Enumerates the direct child storages of this storage.
public IEnumerable<CompoundStorageBuilder> EnumerateStorages()
Returns
- IEnumerable<CompoundStorageBuilder>
The child storages.
EnumerateStreams()
Enumerates the direct child streams of this storage.
public IEnumerable<CompoundStreamBuilder> EnumerateStreams()
Returns
- IEnumerable<CompoundStreamBuilder>
The child streams.
FromFile(CompoundFile, bool)
Creates a root storage tree that mirrors the contents of an open compound file.
public static CompoundStorageBuilder FromFile(CompoundFile file, bool lazy = false)
Parameters
fileCompoundFileThe compound file to copy.
lazyboolfalse (the default) to copy every stream payload into memory, producing a fully detached tree; true to build deferred stream nodes that read their payloads on demand from
file. When true the file must remain open for as long as the tree (or any clone of its nodes) is read or serialized.
Returns
- CompoundStorageBuilder
A root CompoundStorageBuilder that mirrors the file's contents.
Exceptions
- ArgumentNullException
Thrown when
fileis null.- CompoundFileFormatException
Thrown when a stream's sector chain is malformed.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<KeyValuePair<string, CompoundEntryBuilder>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<string, CompoundEntryBuilder>>
An enumerator that can be used to iterate through the collection.
Load(Stream)
Creates a root storage tree that mirrors the contents of a compound file read from a stream.
public static CompoundStorageBuilder Load(Stream source)
Parameters
sourceStreamThe stream containing the compound file; read from its current position to the end.
Returns
- CompoundStorageBuilder
A root CompoundStorageBuilder that mirrors the file's contents.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.- CompoundFileFormatException
Thrown when the stream is not a well-formed compound file.
Remove(string)
Removes the element with the specified key from the IDictionary<TKey, TValue>.
public bool Remove(string key)
Parameters
keystringThe key of the element to remove.
Returns
- bool
true if the element is successfully removed; otherwise, false. This method also returns false if
keywas not found in the original IDictionary<TKey, TValue>.
Exceptions
- ArgumentNullException
keyis null.- NotSupportedException
The IDictionary<TKey, TValue> is read-only.
Rename(string, string)
Renames a child entry.
public void Rename(string oldName, string newName)
Parameters
Exceptions
- CompoundFileSerializationException
Thrown when
newNameis invalid or already present, or when no child namedoldNameexists.
Save(string, CompoundBuildOptions)
Serializes this storage tree to a new file at the supplied path, overwriting any existing file.
public void Save(string path, CompoundBuildOptions options = default)
Parameters
pathstringThe path of the file to create.
optionsCompoundBuildOptionsThe options controlling the output layout.
Exceptions
- ArgumentNullException
Thrown when
pathis null.- CompoundFileSerializationException
Thrown when the tree cannot be represented.
ToArray(CompoundBuildOptions)
Serializes this storage tree to a compound-file byte array.
public byte[] ToArray(CompoundBuildOptions options = default)
Parameters
optionsCompoundBuildOptionsThe options controlling the output layout.
Returns
- byte[]
The complete compound-file content.
Exceptions
- CompoundFileSerializationException
Thrown when the tree cannot be represented.
TryGetStorage(string, out CompoundStorageBuilder)
Attempts to get the child storage with the specified name.
public bool TryGetStorage(string name, out CompoundStorageBuilder storage)
Parameters
namestringThe storage name.
storageCompoundStorageBuilderWhen this method returns true, the matching storage; otherwise null.
Returns
TryGetStream(string, out CompoundStreamBuilder)
Attempts to get the child stream with the specified name.
public bool TryGetStream(string name, out CompoundStreamBuilder stream)
Parameters
namestringThe stream name.
streamCompoundStreamBuilderWhen this method returns true, the matching stream; otherwise null.
Returns
TryGetValue(string, out CompoundEntryBuilder)
Gets the value associated with the specified key.
public bool TryGetValue(string key, out CompoundEntryBuilder value)
Parameters
keystringThe key whose value to get.
valueCompoundEntryBuilderWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the
valueparameter. This parameter is passed uninitialized.
Returns
- bool
true if the object that implements IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
WriteTo(IBufferWriter<byte>, CompoundBuildOptions)
Serializes this storage tree to the supplied buffer writer.
public void WriteTo(IBufferWriter<byte> output, CompoundBuildOptions options = default)
Parameters
outputIBufferWriter<byte>The buffer writer to write the compound file to.
optionsCompoundBuildOptionsThe options controlling the output layout.
Exceptions
- ArgumentNullException
Thrown when
outputis null.- CompoundFileSerializationException
Thrown when the tree cannot be represented.
WriteTo(Stream, CompoundBuildOptions)
Serializes this storage tree to the supplied stream.
public void WriteTo(Stream destination, CompoundBuildOptions options = default)
Parameters
destinationStreamThe stream to write the compound file to.
optionsCompoundBuildOptionsThe options controlling the output layout.
Exceptions
- ArgumentNullException
Thrown when
destinationis null.- CompoundFileSerializationException
Thrown when the tree cannot be represented.
Explicit Interface Implementations
ICollection<KeyValuePair<string, CompoundEntryBuilder>>.Add(KeyValuePair<string, CompoundEntryBuilder>)
Adds an item to the ICollection<T>.
void ICollection<KeyValuePair<string, CompoundEntryBuilder>>.Add(KeyValuePair<string, CompoundEntryBuilder> item)
Parameters
itemKeyValuePair<string, CompoundEntryBuilder>The object to add to the ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
ICollection<KeyValuePair<string, CompoundEntryBuilder>>.Contains(KeyValuePair<string, CompoundEntryBuilder>)
Determines whether the ICollection<T> contains a specific value.
bool ICollection<KeyValuePair<string, CompoundEntryBuilder>>.Contains(KeyValuePair<string, CompoundEntryBuilder> item)
Parameters
itemKeyValuePair<string, CompoundEntryBuilder>The object to locate in the ICollection<T>.
Returns
- bool
true if
itemis found in the ICollection<T>; otherwise, false.
ICollection<KeyValuePair<string, CompoundEntryBuilder>>.CopyTo(KeyValuePair<string, CompoundEntryBuilder>[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
void ICollection<KeyValuePair<string, CompoundEntryBuilder>>.CopyTo(KeyValuePair<string, CompoundEntryBuilder>[] array, int arrayIndex)
Parameters
arrayKeyValuePair<string, CompoundEntryBuilder>[]The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.
arrayIndexintThe zero-based index in
arrayat which copying begins.
Exceptions
- ArgumentNullException
arrayis null.- ArgumentOutOfRangeException
arrayIndexis less than 0.- ArgumentException
The number of elements in the source ICollection<T> is greater than the available space from
arrayIndexto the end of the destinationarray.
ICollection<KeyValuePair<string, CompoundEntryBuilder>>.IsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
bool ICollection<KeyValuePair<string, CompoundEntryBuilder>>.IsReadOnly { get; }
Returns
- bool
true if the ICollection<T> is read-only; otherwise, false.
ICollection<KeyValuePair<string, CompoundEntryBuilder>>.Remove(KeyValuePair<string, CompoundEntryBuilder>)
Removes the first occurrence of a specific object from the ICollection<T>.
bool ICollection<KeyValuePair<string, CompoundEntryBuilder>>.Remove(KeyValuePair<string, CompoundEntryBuilder> item)
Parameters
itemKeyValuePair<string, CompoundEntryBuilder>The object to remove from the ICollection<T>.
Returns
- bool
true if
itemwas successfully removed from the ICollection<T>; otherwise, false. This method also returns false ifitemis not found in the original ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through a collection.
IEnumerator IEnumerable.GetEnumerator()
Returns
- IEnumerator
An IEnumerator object that can be used to iterate through the collection.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |