ComponentValue Struct

A value of the component model, converted from or to the memory of a component by the canonical ABI. The values are immutable; their interpretation depends on their type: a record and a tuple are the values of their fields, a variant, an enum, an option and a result are a case (a label and an optional payload).

public readonly struct ComponentValue : IEquatable<ComponentValue>
Implements

Properties

NameDescription
CaseNameGets the label of a case of a variant, an enum, an option or a result.
KindGets the kind of the value.
NoneValueGets the none case of an option.
PayloadGets the payload of a case, or null.

Gets the label of a case of a variant, an enum, an option or a result.

public string CaseName { get; }

Property value

string

Gets the kind of the value.

public ComponentValueKind Kind { get; }

Property value

ComponentValueKind

Gets the none case of an option.

public static ComponentValue NoneValue { get; }

Property value

ComponentValue

Gets the payload of a case, or null.

public ComponentValue? Payload { get; }

Property value

ComponentValue?

Methods

NameDescription
AsBool()Returns the value of a bool.
AsBytes()Returns the bytes of a list of u8.
AsChar()Returns the value of a char.
AsErrorContext()Returns the error-context.
AsF32()Returns the value of an f32.
AsF64()Returns the value of an f64.
AsFlags()Returns the set labels of a flags value.
AsFutureReader()Returns the readable end of a future, which the host reads.
AsList()Returns the elements of a list.
AsRecord()Returns the values of the fields of a record or a tuple.
AsResource()Returns the resource of a handle.
AsS16()Returns the value of an s16.
AsS32()Returns the value of an s32.
AsS64()Returns the value of an s64.
AsS8()Returns the value of an s8.
AsStreamReader()Returns the readable end of a stream, which the host reads.
AsString()Returns the value of a string.
AsU16()Returns the value of a u16.
AsU32()Returns the value of a u32.
AsU64()Returns the value of a u64.
AsU8()Returns the value of a u8.
Equals(ComponentValue)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Indicates whether this instance and a specified object are equal.
Error(ComponentValue?)Creates the error case of a result.
FromBool(bool)Creates a bool.
FromBytes(ReadOnlySpan<byte>)Creates a list of u8 from bytes, which are copied.
FromCase(string, ComponentValue?)Creates a case of a variant, an enum, an option or a result.
FromChar(Rune)Creates a char.
FromEnum(string)Creates a case of an enum.
FromErrorContext(ComponentErrorContext)Creates an error-context.
FromF32(float)Creates an f32.
FromF64(double)Creates an f64.
FromFlags(IEnumerable<string>)Creates a flags value from the set labels.
FromList(IEnumerable<ComponentValue>)Creates a list.
FromOption(ComponentValue?)Creates an option: some with the value, or none.
FromRecord(ReadOnlySpan<ComponentValue>)Creates a record or a tuple from the values of its fields, in the order of the type.
FromResource(ComponentResource)Creates a handle to a resource, for an own or a borrow type.
FromS16(short)Creates an s16.
FromS32(int)Creates an s32.
FromS64(long)Creates an s64.
FromS8(sbyte)Creates an s8.
FromString(string)Creates a string. A string with an unpaired surrogate cannot be given to a component.
FromTuple(ReadOnlySpan<ComponentValue>)Creates a tuple from the values of its fields.
FromU16(ushort)Creates a u16.
FromU32(uint)Creates a u32.
FromU64(ulong)Creates a u64.
FromU8(byte)Creates a u8.
GetHashCode()Returns the hash code for this instance.
IsCase(string)Returns whether the value is the case name.
Ok(ComponentValue?)Creates the ok case of a result.
Some(ComponentValue)Creates the some case of an option.
ToString()Returns the value in a form similar to the text format.

Returns the value of a bool.

public bool AsBool()

Returns

bool

Returns the bytes of a list of u8.

public byte[] AsBytes()

Returns

byte[]

Returns the value of a char.

public Rune AsChar()

Returns

Rune

AsErrorContext()

ComponentValue.cs

Returns the error-context.

public ComponentErrorContext AsErrorContext()

Returns the value of an f32.

public float AsF32()

Returns

float

Returns the value of an f64.

public double AsF64()

Returns

double

Returns the set labels of a flags value.

public IReadOnlyList<string> AsFlags()

AsFutureReader()

ComponentValue.cs

Returns the readable end of a future, which the host reads.

public ComponentFutureReader AsFutureReader()

Returns the elements of a list.

public IReadOnlyList<ComponentValue> AsList()

Returns the values of the fields of a record or a tuple.

public IReadOnlyList<ComponentValue> AsRecord()

AsResource()

ComponentValue.cs

Returns the resource of a handle.

public ComponentResource AsResource()

Returns the value of an s16.

public short AsS16()

Returns

short

Returns the value of an s32.

public int AsS32()

Returns

int

Returns the value of an s64.

public long AsS64()

Returns

long

Returns the value of an s8.

public sbyte AsS8()

Returns

sbyte

AsStreamReader()

ComponentValue.cs

Returns the readable end of a stream, which the host reads.

public ComponentStreamReader AsStreamReader()

Returns the value of a string.

public string AsString()

Returns

string

Returns the value of a u16.

public ushort AsU16()

Returns

ushort

Returns the value of a u32.

public uint AsU32()

Returns

uint

Returns the value of a u64.

public ulong AsU64()

Returns

ulong

Returns the value of a u8.

public byte AsU8()

Returns

byte

Equals overloads

Equals(ComponentValue)

ComponentValue.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(ComponentValue other)
Parameters
other ComponentValue
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

ComponentValue.cs

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current instance.
Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.

Error(ComponentValue?)

ComponentValue.cs

Creates the error case of a result.

public static ComponentValue Error(ComponentValue? value = null)

Parameters

value ComponentValue?

Returns

ComponentValue

FromBool(bool)

ComponentValue.cs

Creates a bool.

public static ComponentValue FromBool(bool value)

Parameters

value bool

Returns

ComponentValue

FromBytes(ReadOnlySpan<byte>)

ComponentValue.cs

Creates a list of u8 from bytes, which are copied.

public static ComponentValue FromBytes(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

Returns

ComponentValue

FromCase(string, ComponentValue?)

ComponentValue.cs

Creates a case of a variant, an enum, an option or a result.

public static ComponentValue FromCase(string name, ComponentValue? payload = null)

Parameters

name string
The label of the case.
payload ComponentValue?
The payload of the case, or null.

Returns

ComponentValue

FromChar(Rune)

ComponentValue.cs

Creates a char.

public static ComponentValue FromChar(Rune value)

Parameters

value Rune

Returns

ComponentValue

FromEnum(string)

ComponentValue.cs

Creates a case of an enum.

public static ComponentValue FromEnum(string name)

Parameters

name string

Returns

ComponentValue

FromErrorContext(ComponentErrorContext)

ComponentValue.cs

Creates an error-context.

public static ComponentValue FromErrorContext(ComponentErrorContext errorContext)

Parameters

errorContext ComponentErrorContext

Returns

ComponentValue

FromF32(float)

ComponentValue.cs

Creates an f32.

public static ComponentValue FromF32(float value)

Parameters

value float

Returns

ComponentValue

FromF64(double)

ComponentValue.cs

Creates an f64.

public static ComponentValue FromF64(double value)

Parameters

value double

Returns

ComponentValue

FromFlags(IEnumerable<string>)

ComponentValue.cs

Creates a flags value from the set labels.

public static ComponentValue FromFlags(IEnumerable<string> labels)

Parameters

labels IEnumerable<string>

Returns

ComponentValue

FromList(IEnumerable<ComponentValue>)

ComponentValue.cs

Creates a list.

public static ComponentValue FromList(IEnumerable<ComponentValue> values)

FromOption(ComponentValue?)

ComponentValue.cs

Creates an option: some with the value, or none.

public static ComponentValue FromOption(ComponentValue? value)

Parameters

value ComponentValue?

Returns

ComponentValue

FromRecord(ReadOnlySpan<ComponentValue>)

ComponentValue.cs

Creates a record or a tuple from the values of its fields, in the order of the type.

public static ComponentValue FromRecord(params scoped ReadOnlySpan<ComponentValue> fields)

FromResource(ComponentResource)

ComponentValue.cs

Creates a handle to a resource, for an own or a borrow type.

public static ComponentValue FromResource(ComponentResource resource)

Parameters

resource ComponentResource

Returns

ComponentValue

FromS16(short)

ComponentValue.cs

Creates an s16.

public static ComponentValue FromS16(short value)

Parameters

value short

Returns

ComponentValue

FromS32(int)

ComponentValue.cs

Creates an s32.

public static ComponentValue FromS32(int value)

Parameters

value int

Returns

ComponentValue

FromS64(long)

ComponentValue.cs

Creates an s64.

public static ComponentValue FromS64(long value)

Parameters

value long

Returns

ComponentValue

FromS8(sbyte)

ComponentValue.cs

Creates an s8.

public static ComponentValue FromS8(sbyte value)

Parameters

value sbyte

Returns

ComponentValue

FromString(string)

ComponentValue.cs

Creates a string. A string with an unpaired surrogate cannot be given to a component.

public static ComponentValue FromString(string value)

Parameters

value string

Returns

ComponentValue

FromTuple(ReadOnlySpan<ComponentValue>)

ComponentValue.cs

Creates a tuple from the values of its fields.

public static ComponentValue FromTuple(params scoped ReadOnlySpan<ComponentValue> fields)

FromU16(ushort)

ComponentValue.cs

Creates a u16.

public static ComponentValue FromU16(ushort value)

Parameters

value ushort

Returns

ComponentValue

FromU32(uint)

ComponentValue.cs

Creates a u32.

public static ComponentValue FromU32(uint value)

Parameters

value uint

Returns

ComponentValue

FromU64(ulong)

ComponentValue.cs

Creates a u64.

public static ComponentValue FromU64(ulong value)

Parameters

value ulong

Returns

ComponentValue

FromU8(byte)

ComponentValue.cs

Creates a u8.

public static ComponentValue FromU8(byte value)

Parameters

value byte

Returns

ComponentValue

GetHashCode()

ComponentValue.cs

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int A 32-bit signed integer that is the hash code for this instance.

IsCase(string)

ComponentValue.cs

Returns whether the value is the case name.

public bool IsCase(string name)

Parameters

name string

Returns

bool

Ok(ComponentValue?)

ComponentValue.cs

Creates the ok case of a result.

public static ComponentValue Ok(ComponentValue? value = null)

Parameters

value ComponentValue?

Returns

ComponentValue

Some(ComponentValue)

ComponentValue.cs

Creates the some case of an option.

public static ComponentValue Some(ComponentValue value)

Parameters

value ComponentValue

Returns

ComponentValue

Returns the value in a form similar to the text format.

public override string ToString()

Returns

string

Operators

NameDescription
operator ==(ComponentValue, ComponentValue)Indicates whether two values are equal.
operator !=(ComponentValue, ComponentValue)Indicates whether two values are not equal.

operator ==(ComponentValue, ComponentValue)

ComponentValue.cs

Indicates whether two values are equal.

public static bool operator ==(ComponentValue left, ComponentValue right)

Parameters

left ComponentValue
right ComponentValue

Returns

bool

operator !=(ComponentValue, ComponentValue)

ComponentValue.cs

Indicates whether two values are not equal.

public static bool operator !=(ComponentValue left, ComponentValue right)

Parameters

left ComponentValue
right ComponentValue

Returns

bool