Class VBUserDefinedTypeValue
Represents a value of a VBUserDefinedType. Like VBObjectValue the value is a MemoryAddress — a UDT has location identity and is never passed by value.
public record VBUserDefinedTypeValue : VBTypedValue, IEquatable<VBTypedValue>, IVBTypedValue<VBUserDefinedTypeValue, MemoryAddress>, IEquatable<IVBTypedValue<VBUserDefinedTypeValue, MemoryAddress>>, IEquatable<VBUserDefinedTypeValue>
- Inheritance
-
VBUserDefinedTypeValue
- Implements
- Inherited Members
Remarks
👉 The field store is a flat block of cells in declaration order, exactly as
VBArrayValue holds its elements and for the same reason: a UDT's real content is its
fields, and a scalar IRuntimeValue has nowhere to hold them. Declaration order is not an
implementation detail — it is the order MS-VBAL §5.4.5.11 writes a record in, and the
order VBUserDefinedTypeLayout assigns offsets in.
Constructors
VBUserDefinedTypeValue(VBUserDefinedType)
public VBUserDefinedTypeValue(VBUserDefinedType typeInfo)
Parameters
typeInfoVBUserDefinedType
VBUserDefinedTypeValue(IBindingHandle, VBUserDefinedType)
public VBUserDefinedTypeValue(IBindingHandle handle, VBUserDefinedType typeInfo)
Parameters
handleIBindingHandletypeInfoVBUserDefinedType
VBUserDefinedTypeValue(VBUserDefinedTypeValue)
protected VBUserDefinedTypeValue(VBUserDefinedTypeValue original)
Parameters
originalVBUserDefinedTypeValue
VBUserDefinedTypeValue(MemoryAddress, VBUserDefinedType)
public VBUserDefinedTypeValue(MemoryAddress reference, VBUserDefinedType typeInfo)
Parameters
referenceMemoryAddresstypeInfoVBUserDefinedType
Properties
Fields
This type's fields, in declaration order — the same symbols Fields() reports, held here so that a value can name its own fields without resolving its type again.
public ImmutableArray<VBUserDefinedTypeFieldSymbol> Fields { get; init; }
Property Value
this[string]
The value of the field named name, or null when there is no such field.
public VBTypedValue? this[string name] { get; }
Parameters
namestringThe field name, compared case-insensitively as VBA compares identifiers.
Property Value
Layout
Where each of this value's fields sits in memory.
public VBUserDefinedTypeLayout Layout { get; }
Property Value
Size
The in-memory size of this UDT, MS-VBA's own padding included — what LenB reports
(MS-VBAL §6.1.2.11).
public override int Size { get; }
Property Value
Remarks
Not the size a Put statement writes, which is the unpadded concatenation of the fields and is
what Len reports of a UDT instead: "Len returns the size as it will be written to the
file". VBUserDefinedTypeLayout holds the padding rule and the reasoning behind it.
Value
Gets the underlying managed value corresponding to this typed value.
public MemoryAddress Value { get; }
Property Value
Methods
Equals(IVBTypedValue<VBUserDefinedTypeValue, MemoryAddress>?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(IVBTypedValue<VBUserDefinedTypeValue, MemoryAddress>? other)
Parameters
otherIVBTypedValue<VBUserDefinedTypeValue, MemoryAddress>An object to compare with this object.
Returns
FieldAt(int)
The value of the field at index in declaration order, or null when there is
no field there.
public VBTypedValue? FieldAt(int index)
Parameters
indexint
Returns
Remarks
Declaration order is what a record is written and read in, so a caller walking the fields to serialize them wants this rather than the name-keyed indexer.
GetFieldHandle(string)
The binding of the field named name, or null when there is no such field.
public IBindingHandle? GetFieldHandle(string name)
Parameters
namestringThe field name, compared case-insensitively.
Returns
Remarks
What a ByRef argument of a UDT field needs, and what an assignment to one writes through —
neither of which constructs a value, so neither goes through the indexer.
TryAllocateIn(ISessionStorage, out VBUserDefinedTypeValue?)
Reserves storage sized for this UDT through storage, and returns a copy of
this value bound to the resulting address — a UDT's identity is its address, so the
allocated copy self-reports the very address it was allocated at.
public bool TryAllocateIn(ISessionStorage storage, out VBUserDefinedTypeValue? allocated)
Parameters
storageISessionStorageallocatedVBUserDefinedTypeValue
Returns
- bool
falseif the underlying memory space is exhausted.
TrySetField(string, VBTypedValue)
Replaces the value of the field named name. Mutates the cell in place — field
storage is mutable, the way array element storage is.
public bool TrySetField(string name, VBTypedValue value)
Parameters
namestringThe field name, compared case-insensitively.
valueVBTypedValueThe value to store.
Returns
- bool
falsewhen there is no such field.
TrySetFieldAt(int, VBTypedValue)
Replaces the value of the field at index in declaration order.
public bool TrySetFieldAt(int index, VBTypedValue value)
Parameters
indexintThe field's position in declaration order.
valueVBTypedValueThe value to store.
Returns
- bool
falsewhen there is no field there.