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).
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
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;
1252when 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
propertyIdintThe 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
sectionOlePropertySectionThe section to add.
Exceptions
- ArgumentNullException
Thrown when
sectionis null.
Parse(ReadOnlyMemory<byte>)
Parses an OLE property set from its serialized bytes.
public static OlePropertySet Parse(ReadOnlyMemory<byte> data)
Parameters
dataReadOnlyMemory<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
streamStreamThe stream containing the property-set bytes.
Returns
- OlePropertySet
The parsed OlePropertySet.
Exceptions
- ArgumentNullException
Thrown when
streamis 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
propertyIdintThe property identifier (PID).
valueOlePropertyValueWhen this method returns true, the property value; otherwise null.
Returns
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
outputIBufferWriter<byte>The buffer writer to write to.
Exceptions
- ArgumentNullException
Thrown when
outputis null.
WriteTo(Stream)
Serializes the property set to its OLE byte form, written to the supplied stream.
public void WriteTo(Stream stream)
Parameters
streamStreamThe stream to write the property-set bytes to.
Exceptions
- ArgumentNullException
Thrown when
streamis null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |