Table of Contents

Struct VariantValue

Namespace
Tmds.DBus.Protocol
Assembly
Tmds.DBus.Protocol.dll

Represents a D-Bus variant value for reading or writing.

public readonly struct VariantValue : IEquatable<VariantValue>
Implements
Inherited Members

Remarks

Constructing a VariantValue for writing with WriteVariant(VariantValue):

The following types support implicit conversion to VariantValue: byte, bool, short, ushort, int, uint, long, ulong, double, string, ObjectPath, Signature. These conversions may also be performed explicitly using the corresponding static methods: Byte(byte), Bool(bool), Int16(short), UInt16(ushort), Int32(int), UInt32(uint), Int64(long), UInt64(ulong), Double(double), String(string), ObjectPath(ObjectPath), Signature(Signature).

Array, struct, and dictionary values can be strongly-typed using the Array<T>, Struct<T1> (and generic variants), and Dict<TKey, TValue> classes. These classes implicitly convert to VariantValue.

For arrays, static Array methods (and related overloads) allow creating a VariantValue directly from array or List<T> instances of byte, short, ushort, int, uint, long, ulong, double, string, ObjectPath, bool, Signature, SafeHandle, and VariantValue.

For structs, static Struct methods (and related overloads) allow creating a VariantValue directly from VariantValue instances for its fields.

To wrap a value in a variant container, use Variant(VariantValue). For Unix file descriptors, use UnixFd(SafeHandle).

Interpreting a VariantValue read with ReadVariantValue():

Type returns the value type. For Array, use ItemType to determine the array element type. For Dictionary, use KeyType and ValueType to determine the dictionary key and value types. Count returns the number of items for Array, Struct, or Dictionary types.

Use typed getters to retrieve values: GetByte(), GetBool(), GetInt16(), GetUInt16(), GetInt32(), GetUInt32(), GetInt64(), GetUInt64(), GetDouble(), GetString(), GetObjectPath(), GetSignature().

For structs, use GetItem(int) to access individual elements by index.

For arrays, use GetItem(int) to access individual elements by index, or GetArray<T>() to obtain a T[] array.

For dictionaries, use GetDictionaryEntry(int) to access individual entries by index, or GetDictionary<TKey, TValue>() to obtain a Dictionary<TKey, TValue>.

To unwrap a variant container, use GetVariantValue(). For Unix file descriptors, use ReadHandle<T>().

Properties

Count

Gets the number of elements in a Array, Struct, or Dictionary type.

public int Count { get; }

Property Value

int

The element count, or -1 when not a countable type.

ItemType

Gets the type of array items for a Array type.

public VariantValueType ItemType { get; }

Property Value

VariantValueType

The item type, or Invalid if this is not an array.

KeyType

Gets the type of dictionary keys for a Dictionary type.

public VariantValueType KeyType { get; }

Property Value

VariantValueType

The key type, or Invalid if this is not a dictionary.

Type

Gets the type of the value.

public VariantValueType Type { get; }

Property Value

VariantValueType

ValueType

Gets the type of dictionary values for a Dictionary type.

public VariantValueType ValueType { get; }

Property Value

VariantValueType

The value type, or Invalid if this is not a dictionary.

Methods

Array(bool[])

Creates an array VariantValue from a boolean array.

public static VariantValue Array(bool[] items)

Parameters

items bool[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(byte[])

Creates an array VariantValue from a byte array.

public static VariantValue Array(byte[] items)

Parameters

items byte[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<bool>)

Creates an array VariantValue from a list of boolean values.

public static VariantValue Array(List<bool> items)

Parameters

items List<bool>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<byte>)

Creates an array VariantValue from a list of bytes.

public static VariantValue Array(List<byte> items)

Parameters

items List<byte>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<double>)

Creates an array VariantValue from a list of doubles.

public static VariantValue Array(List<double> items)

Parameters

items List<double>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<short>)

Creates an array VariantValue from a list of signed 16-bit integers.

public static VariantValue Array(List<short> items)

Parameters

items List<short>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<int>)

Creates an array VariantValue from a list of signed 32-bit integers.

public static VariantValue Array(List<int> items)

Parameters

items List<int>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<long>)

Creates an array VariantValue from a list of signed 64-bit integers.

public static VariantValue Array(List<long> items)

Parameters

items List<long>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<SafeHandle>)

Creates an array VariantValue from a list of Unix file descriptor handles.

public static VariantValue Array(List<SafeHandle> items)

Parameters

items List<SafeHandle>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<string>)

Creates an array VariantValue from a list of strings.

public static VariantValue Array(List<string> items)

Parameters

items List<string>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<ushort>)

Creates an array VariantValue from a list of unsigned 16-bit integers.

public static VariantValue Array(List<ushort> items)

Parameters

items List<ushort>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<uint>)

Creates an array VariantValue from a list of unsigned 32-bit integers.

public static VariantValue Array(List<uint> items)

Parameters

items List<uint>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<ulong>)

Creates an array VariantValue from a list of unsigned 64-bit integers.

public static VariantValue Array(List<ulong> items)

Parameters

items List<ulong>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<ObjectPath>)

Creates an array VariantValue from a list of ObjectPath(ObjectPath) values.

public static VariantValue Array(List<ObjectPath> items)

Parameters

items List<ObjectPath>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(List<Signature>)

Creates an array VariantValue from a list of Signature values.

public static VariantValue Array(List<Signature> items)

Parameters

items List<Signature>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(double[])

Creates an array VariantValue from a double array.

public static VariantValue Array(double[] items)

Parameters

items double[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(short[])

Creates an array VariantValue from a signed 16-bit integer array.

public static VariantValue Array(short[] items)

Parameters

items short[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(int[])

Creates an array VariantValue from a signed 32-bit integer array.

public static VariantValue Array(int[] items)

Parameters

items int[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(long[])

Creates an array VariantValue from a signed 64-bit integer array.

public static VariantValue Array(long[] items)

Parameters

items long[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(SafeHandle[])

Creates an array VariantValue from a Unix file descriptor handle array.

public static VariantValue Array(SafeHandle[] items)

Parameters

items SafeHandle[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(string[])

Creates an array VariantValue from a string array.

public static VariantValue Array(string[] items)

Parameters

items string[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(ushort[])

Creates an array VariantValue from an unsigned 16-bit integer array.

public static VariantValue Array(ushort[] items)

Parameters

items ushort[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(uint[])

Creates an array VariantValue from an unsigned 32-bit integer array.

public static VariantValue Array(uint[] items)

Parameters

items uint[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(ulong[])

Creates an array VariantValue from an unsigned 64-bit integer array.

public static VariantValue Array(ulong[] items)

Parameters

items ulong[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(ObjectPath[])

Creates an array VariantValue from an ObjectPath(ObjectPath) array.

public static VariantValue Array(ObjectPath[] items)

Parameters

items ObjectPath[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Array(Signature[])

Creates an array VariantValue from a Signature array.

public static VariantValue Array(Signature[] items)

Parameters

items Signature[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

ArrayOfVariant(List<VariantValue>)

Creates an array VariantValue from a list of VariantValue values.

public static VariantValue ArrayOfVariant(List<VariantValue> items)

Parameters

items List<VariantValue>

Returns

VariantValue

Remarks

The list should not be mutated after creation because it may be stored directly in the VariantValue without copying.

ArrayOfVariant(VariantValue[])

Creates an array VariantValue from a VariantValue array.

public static VariantValue ArrayOfVariant(VariantValue[] items)

Parameters

items VariantValue[]

Returns

VariantValue

Remarks

The array should not be mutated after creation because it may be stored directly in the VariantValue without copying.

Bool(bool)

Creates a VariantValue from a boolean value.

public static VariantValue Bool(bool value)

Parameters

value bool

Returns

VariantValue

Byte(byte)

Creates a VariantValue from a byte value.

public static VariantValue Byte(byte value)

Parameters

value byte

Returns

VariantValue

Double(double)

Creates a VariantValue from a double.

public static VariantValue Double(double value)

Parameters

value double

Returns

VariantValue

Equals(object?)

Determines whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

Equals(VariantValue)

Determines whether this instance and another VariantValue are equal.

public bool Equals(VariantValue other)

Parameters

other VariantValue

Returns

bool

GetArray<T>()

Gets the array value for a Array type.

public T[] GetArray<T>() where T : notnull

Returns

T[]

Type Parameters

T

The type of array elements. Allowed types: byte, bool, short, ushort, int, uint, long, ulong, double, string, ObjectPath(ObjectPath), Signature(Signature), VariantValue, or types derived from SafeHandle.

Remarks

For byte, short, ushort, int, uint, long, ulong, double, string, and ObjectPath(ObjectPath), the underlying array may be returned directly. Mutating the returned array affects the instance.

GetBool()

Gets the boolean value for a Bool type.

public bool GetBool()

Returns

bool

GetByte()

Gets the byte value for a Byte type.

public byte GetByte()

Returns

byte

GetDictionaryEntry(int)

Gets a dictionary entry at the specified index for a Dictionary type.

public KeyValuePair<VariantValue, VariantValue> GetDictionaryEntry(int i)

Parameters

i int

The zero-based index of the entry.

Returns

KeyValuePair<VariantValue, VariantValue>

GetDictionary<TKey, TValue>()

Gets the dictionary value for a Dictionary type.

public Dictionary<TKey, TValue> GetDictionary<TKey, TValue>() where TKey : notnull where TValue : notnull

Returns

Dictionary<TKey, TValue>

Type Parameters

TKey

The type of dictionary keys. Allowed types: byte, bool, short, ushort, int, uint, long, ulong, double, string, ObjectPath(ObjectPath), Signature(Signature), VariantValue, or types derived from SafeHandle.

TValue

The type of dictionary values. Allowed types: byte, bool, short, ushort, int, uint, long, ulong, double, string, ObjectPath(ObjectPath), Signature(Signature), VariantValue, or types derived from SafeHandle.

GetDouble()

Gets the double value for a Double type.

public double GetDouble()

Returns

double

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

GetInt16()

Gets the signed 16-bit integer value for a Int16 type.

public short GetInt16()

Returns

short

GetInt32()

Gets the signed 32-bit integer value for a Int32 type.

public int GetInt32()

Returns

int

GetInt64()

Gets the signed 64-bit integer value for a Int64 type.

public long GetInt64()

Returns

long

GetItem(int)

Gets an item at the specified index for a Array or Struct type.

public VariantValue GetItem(int i)

Parameters

i int

The zero-based index of the item.

Returns

VariantValue

GetObjectPath()

Gets the object path value for a ObjectPath type.

public ObjectPath GetObjectPath()

Returns

ObjectPath

GetObjectPathAsString()

Gets the object path as a string for a ObjectPath type.

public string GetObjectPathAsString()

Returns

string

GetSignature()

Gets the signature value for a Signature type.

public Signature GetSignature()

Returns

Signature

GetString()

Gets the string value for a String type.

public string GetString()

Returns

string

GetUInt16()

Gets the unsigned 16-bit integer value for a UInt16 type.

public ushort GetUInt16()

Returns

ushort

GetUInt32()

Gets the unsigned 32-bit integer value for a UInt32 type.

public uint GetUInt32()

Returns

uint

GetUInt64()

Gets the unsigned 64-bit integer value for a UInt64 type.

public ulong GetUInt64()

Returns

ulong

GetVariantValue()

Unwraps the value for a Variant type.

public VariantValue GetVariantValue()

Returns

VariantValue

Int16(short)

Creates a VariantValue from a signed 16-bit integer.

public static VariantValue Int16(short value)

Parameters

value short

Returns

VariantValue

Int32(int)

Creates a VariantValue from a signed 32-bit integer.

public static VariantValue Int32(int value)

Parameters

value int

Returns

VariantValue

Int64(long)

Creates a VariantValue from a signed 64-bit integer.

public static VariantValue Int64(long value)

Parameters

value long

Returns

VariantValue

ObjectPath(ObjectPath)

Creates a VariantValue from an ObjectPath.

public static VariantValue ObjectPath(ObjectPath value)

Parameters

value ObjectPath

Returns

VariantValue

ReadHandle<T>()

Reads a Unix file descriptor handle for a UnixFd type.

public T ReadHandle<T>() where T : SafeHandle, new()

Returns

T

Type Parameters

T

The SafeHandle type to read. If T is SkipSafeHandle, the method returns a disposed SkipSafeHandle instance without consuming the underlying handle.

Remarks

A handle can only be read once.

Exceptions

DBusReadException

The file descriptor is not present in the message.

DBusUnexpectedValueException

The handle was already read.

Signature(Signature)

Creates a VariantValue from a Signature.

public static VariantValue Signature(Signature value)

Parameters

value Signature

Returns

VariantValue

String(string)

Creates a VariantValue from a string.

public static VariantValue String(string value)

Parameters

value string

Returns

VariantValue

Struct(VariantValue)

Creates a struct VariantValue with 1 field.

public static VariantValue Struct(VariantValue item1)

Parameters

item1 VariantValue

Returns

VariantValue

Struct(VariantValue, VariantValue)

Creates a struct VariantValue with 2 fields.

public static VariantValue Struct(VariantValue item1, VariantValue item2)

Parameters

item1 VariantValue
item2 VariantValue

Returns

VariantValue

Struct(VariantValue, VariantValue, VariantValue)

Creates a struct VariantValue with 3 fields.

public static VariantValue Struct(VariantValue item1, VariantValue item2, VariantValue item3)

Parameters

item1 VariantValue
item2 VariantValue
item3 VariantValue

Returns

VariantValue

Struct(VariantValue, VariantValue, VariantValue, VariantValue)

Creates a struct VariantValue with 4 fields.

public static VariantValue Struct(VariantValue item1, VariantValue item2, VariantValue item3, VariantValue item4)

Parameters

item1 VariantValue
item2 VariantValue
item3 VariantValue
item4 VariantValue

Returns

VariantValue

Struct(VariantValue, VariantValue, VariantValue, VariantValue, VariantValue)

Creates a struct VariantValue with 5 fields.

public static VariantValue Struct(VariantValue item1, VariantValue item2, VariantValue item3, VariantValue item4, VariantValue item5)

Parameters

item1 VariantValue
item2 VariantValue
item3 VariantValue
item4 VariantValue
item5 VariantValue

Returns

VariantValue

Struct(VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue)

Creates a struct VariantValue with 6 fields.

public static VariantValue Struct(VariantValue item1, VariantValue item2, VariantValue item3, VariantValue item4, VariantValue item5, VariantValue item6)

Parameters

item1 VariantValue
item2 VariantValue
item3 VariantValue
item4 VariantValue
item5 VariantValue
item6 VariantValue

Returns

VariantValue

Struct(VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue)

Creates a struct VariantValue with 7 fields.

public static VariantValue Struct(VariantValue item1, VariantValue item2, VariantValue item3, VariantValue item4, VariantValue item5, VariantValue item6, VariantValue item7)

Parameters

item1 VariantValue
item2 VariantValue
item3 VariantValue
item4 VariantValue
item5 VariantValue
item6 VariantValue
item7 VariantValue

Returns

VariantValue

Struct(VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue)

Creates a struct VariantValue with 8 fields.

public static VariantValue Struct(VariantValue item1, VariantValue item2, VariantValue item3, VariantValue item4, VariantValue item5, VariantValue item6, VariantValue item7, VariantValue item8)

Parameters

item1 VariantValue
item2 VariantValue
item3 VariantValue
item4 VariantValue
item5 VariantValue
item6 VariantValue
item7 VariantValue
item8 VariantValue

Returns

VariantValue

Struct(VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue)

Creates a struct VariantValue with 9 fields.

public static VariantValue Struct(VariantValue item1, VariantValue item2, VariantValue item3, VariantValue item4, VariantValue item5, VariantValue item6, VariantValue item7, VariantValue item8, VariantValue item9)

Parameters

item1 VariantValue
item2 VariantValue
item3 VariantValue
item4 VariantValue
item5 VariantValue
item6 VariantValue
item7 VariantValue
item8 VariantValue
item9 VariantValue

Returns

VariantValue

Struct(VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue, VariantValue)

Creates a struct VariantValue with 10 fields.

public static VariantValue Struct(VariantValue item1, VariantValue item2, VariantValue item3, VariantValue item4, VariantValue item5, VariantValue item6, VariantValue item7, VariantValue item8, VariantValue item9, VariantValue item10)

Parameters

item1 VariantValue
item2 VariantValue
item3 VariantValue
item4 VariantValue
item5 VariantValue
item6 VariantValue
item7 VariantValue
item8 VariantValue
item9 VariantValue
item10 VariantValue

Returns

VariantValue

ToString()

Returns a string representation of this variant value.

public override string ToString()

Returns

string

ToString(bool)

Returns a string representation of this variant value.

public string ToString(bool includeTypeSuffix)

Parameters

includeTypeSuffix bool

Whether to include type information in the string.

Returns

string

UInt16(ushort)

Creates a VariantValue from an unsigned 16-bit integer.

public static VariantValue UInt16(ushort value)

Parameters

value ushort

Returns

VariantValue

UInt32(uint)

Creates a VariantValue from an unsigned 32-bit integer.

public static VariantValue UInt32(uint value)

Parameters

value uint

Returns

VariantValue

UInt64(ulong)

Creates a VariantValue from an unsigned 64-bit integer.

public static VariantValue UInt64(ulong value)

Parameters

value ulong

Returns

VariantValue

UnixFd(SafeHandle)

Creates a VariantValue from a Unix file descriptor handle.

public static VariantValue UnixFd(SafeHandle handle)

Parameters

handle SafeHandle

Returns

VariantValue

Variant(VariantValue)

Wraps a VariantValue in a variant container.

public static VariantValue Variant(VariantValue value)

Parameters

value VariantValue

Returns

VariantValue

Operators

operator ==(VariantValue, VariantValue)

Determines whether two VariantValue instances are equal.

public static bool operator ==(VariantValue lhs, VariantValue rhs)

Parameters

lhs VariantValue
rhs VariantValue

Returns

bool

implicit operator VariantValue(bool)

Implicitly converts a boolean value to a VariantValue.

public static implicit operator VariantValue(bool value)

Parameters

value bool

Returns

VariantValue

implicit operator VariantValue(byte)

Implicitly converts a byte value to a VariantValue.

public static implicit operator VariantValue(byte value)

Parameters

value byte

Returns

VariantValue

implicit operator VariantValue(double)

Implicitly converts a double to a VariantValue.

public static implicit operator VariantValue(double value)

Parameters

value double

Returns

VariantValue

implicit operator VariantValue(short)

Implicitly converts a signed 16-bit integer to a VariantValue.

public static implicit operator VariantValue(short value)

Parameters

value short

Returns

VariantValue

implicit operator VariantValue(int)

Implicitly converts a signed 32-bit integer to a VariantValue.

public static implicit operator VariantValue(int value)

Parameters

value int

Returns

VariantValue

implicit operator VariantValue(long)

Implicitly converts a signed 64-bit integer to a VariantValue.

public static implicit operator VariantValue(long value)

Parameters

value long

Returns

VariantValue

implicit operator VariantValue(string)

Implicitly converts a string to a VariantValue.

public static implicit operator VariantValue(string value)

Parameters

value string

Returns

VariantValue

implicit operator VariantValue(ushort)

Implicitly converts an unsigned 16-bit integer to a VariantValue.

public static implicit operator VariantValue(ushort value)

Parameters

value ushort

Returns

VariantValue

implicit operator VariantValue(uint)

Implicitly converts an unsigned 32-bit integer to a VariantValue.

public static implicit operator VariantValue(uint value)

Parameters

value uint

Returns

VariantValue

implicit operator VariantValue(ulong)

Implicitly converts an unsigned 64-bit integer to a VariantValue.

public static implicit operator VariantValue(ulong value)

Parameters

value ulong

Returns

VariantValue

implicit operator VariantValue(ObjectPath)

Implicitly converts an ObjectPath to a VariantValue.

public static implicit operator VariantValue(ObjectPath value)

Parameters

value ObjectPath

Returns

VariantValue

implicit operator VariantValue(Signature)

Implicitly converts a Signature to a VariantValue.

public static implicit operator VariantValue(Signature value)

Parameters

value Signature

Returns

VariantValue

operator !=(VariantValue, VariantValue)

Determines whether two VariantValue instances are not equal.

public static bool operator !=(VariantValue lhs, VariantValue rhs)

Parameters

lhs VariantValue
rhs VariantValue

Returns

bool