Table of Contents

OlePropertySet Class

Definition

Namespace
Bodu.IO.Compound.PropertySets
Assembly
Bodu.IO.Compound.dll
Package
Bodu.IO.Compound 1.0.0
Source
OlePropertySet.cs

Represents a parsed OLE property set - the managed counterpart of the COM IPropertyStorage interface - exposing its sections and the typed values they contain.

public sealed class OlePropertySet
Inheritance
OlePropertySet
Inherited Members
Extension Methods

Remarks

An OLE property set is the serialized form stored in streams such as \x05SummaryInformation. It begins with a header that declares the class identifier and one or two sections, each identified by a format identifier (FMTID) and holding properties keyed by property identifier (PID).

The following example opens a property-set stream, parses it, and reads a property by its identifier.
using Bodu.IO.Compound;
using Bodu.IO.Compound.PropertySets;

using CompoundFile file = CompoundFile.OpenRead("book.xls");
using CompoundStream stream = file.RootStorage.OpenStream(SummaryInformation.StreamName);
OlePropertySet set = OlePropertySet.Parse(stream.AsMemory());

// PID 4 is the author in the summary-information set.
if (set.TryGetValue(propertyId: 4, out OlePropertyValue? author))
    Console.WriteLine(author.AsString());

Constructors

OlePropertySet(Guid, Guid, int)

Initializes a new instance of the OlePropertySet class for authoring, with no sections.

public OlePropertySet(Guid formatId, Guid classId, int codePage)

Parameters

formatId Guid

The format identifier of the first section.

classId Guid

The class identifier to declare in the property-set header.

codePage int

The code page of the first section.

Properties

ClassId

Gets the class identifier declared in the property-set header.

public Guid ClassId { get; }

Property Value

Guid

The property set's class identifier.

CodePage

Gets the code page of the first section.

public int CodePage { get; }

Property Value

int

The first section's code page; 1252 when none is declared.

FormatId

Gets the format identifier (FMTID) of the first section.

public Guid FormatId { get; }

Property Value

Guid

The first section's format identifier.

this[int]

Gets the value of a property from the first section.

public OlePropertyValue? this[int propertyId] { get; }

Parameters

propertyId int

The property identifier (PID).

Property Value

OlePropertyValue

The property value, or null when no such property exists.

Sections

Gets the sections of the property set, in declared order.

public IReadOnlyList<OlePropertySection> Sections { get; }

Property Value

IReadOnlyList<OlePropertySection>

A read-only list of OlePropertySection.

Methods

AddSection(OlePropertySection)

Appends a section to the property set.

public void AddSection(OlePropertySection section)

Parameters

section OlePropertySection

The section to add.

Exceptions

ArgumentNullException

Thrown when section is null.

Parse(ReadOnlyMemory<byte>)

Parses an OLE property set from its serialized bytes.

public static OlePropertySet Parse(ReadOnlyMemory<byte> data)

Parameters

data ReadOnlyMemory<byte>

The raw bytes of the property-set stream.

Returns

OlePropertySet

The parsed OlePropertySet.

Exceptions

CompoundFileFormatException

Thrown when the data is not a well-formed property set.

Read(Stream)

Reads and parses an OLE property set from a stream, consuming it to the end.

public static OlePropertySet Read(Stream stream)

Parameters

stream Stream

The stream containing the property-set bytes.

Returns

OlePropertySet

The parsed OlePropertySet.

Exceptions

ArgumentNullException

Thrown when stream is null.

CompoundFileFormatException

Thrown when the data is not a well-formed property set.

ToArray()

Serializes the property set to its OLE byte form.

public byte[] ToArray()

Returns

byte[]

The serialized property-set bytes.

TryGetValue(int, out OlePropertyValue)

Attempts to get the value of a property from the first section.

public bool TryGetValue(int propertyId, out OlePropertyValue value)

Parameters

propertyId int

The property identifier (PID).

value OlePropertyValue

When this method returns true, the property value; otherwise null.

Returns

bool

true when the property exists in the first section; otherwise false.

WriteTo(IBufferWriter<byte>)

Serializes the property set to its OLE byte form, written to the supplied buffer writer.

public void WriteTo(IBufferWriter<byte> output)

Parameters

output IBufferWriter<byte>

The buffer writer to write to.

Exceptions

ArgumentNullException

Thrown when output is null.

WriteTo(Stream)

Serializes the property set to its OLE byte form, written to the supplied stream.

public void WriteTo(Stream stream)

Parameters

stream Stream

The stream to write the property-set bytes to.

Exceptions

ArgumentNullException

Thrown when stream is null.

Applies to

ProductVersions
.NET8, 10