Struct VariantValue
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
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
itemsbool[]
Returns
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
itemsbyte[]
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
itemsList<SafeHandle>
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
itemsList<ObjectPath>
Returns
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
Returns
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
itemsdouble[]
Returns
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
itemsshort[]
Returns
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
itemsint[]
Returns
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
itemslong[]
Returns
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
itemsSafeHandle[]
Returns
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
itemsstring[]
Returns
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
itemsushort[]
Returns
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
itemsuint[]
Returns
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
itemsulong[]
Returns
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
itemsObjectPath[]
Returns
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
itemsSignature[]
Returns
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
itemsList<VariantValue>
Returns
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
itemsVariantValue[]
Returns
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
valuebool
Returns
Byte(byte)
Creates a VariantValue from a byte value.
public static VariantValue Byte(byte value)
Parameters
valuebyte
Returns
Double(double)
Creates a VariantValue from a double.
public static VariantValue Double(double value)
Parameters
valuedouble
Returns
Equals(object?)
Determines whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobject
Returns
Equals(VariantValue)
Determines whether this instance and another VariantValue are equal.
public bool Equals(VariantValue other)
Parameters
otherVariantValue
Returns
GetArray<T>()
Gets the array value for a Array type.
public T[] GetArray<T>() where T : notnull
Returns
- T[]
Type Parameters
TThe 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
GetByte()
Gets the byte value for a Byte type.
public byte GetByte()
Returns
GetDictionaryEntry(int)
Gets a dictionary entry at the specified index for a Dictionary type.
public KeyValuePair<VariantValue, VariantValue> GetDictionaryEntry(int i)
Parameters
iintThe zero-based index of the entry.
Returns
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
TKeyThe 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.
TValueThe 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
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
GetInt16()
Gets the signed 16-bit integer value for a Int16 type.
public short GetInt16()
Returns
GetInt32()
Gets the signed 32-bit integer value for a Int32 type.
public int GetInt32()
Returns
GetInt64()
Gets the signed 64-bit integer value for a Int64 type.
public long GetInt64()
Returns
GetItem(int)
public VariantValue GetItem(int i)
Parameters
iintThe zero-based index of the item.
Returns
GetObjectPath()
Gets the object path value for a ObjectPath type.
public ObjectPath GetObjectPath()
Returns
GetObjectPathAsString()
Gets the object path as a string for a ObjectPath type.
public string GetObjectPathAsString()
Returns
GetSignature()
Gets the signature value for a Signature type.
public Signature GetSignature()
Returns
GetString()
Gets the string value for a String type.
public string GetString()
Returns
GetUInt16()
Gets the unsigned 16-bit integer value for a UInt16 type.
public ushort GetUInt16()
Returns
GetUInt32()
Gets the unsigned 32-bit integer value for a UInt32 type.
public uint GetUInt32()
Returns
GetUInt64()
Gets the unsigned 64-bit integer value for a UInt64 type.
public ulong GetUInt64()
Returns
GetVariantValue()
Unwraps the value for a Variant type.
public VariantValue GetVariantValue()
Returns
Int16(short)
Creates a VariantValue from a signed 16-bit integer.
public static VariantValue Int16(short value)
Parameters
valueshort
Returns
Int32(int)
Creates a VariantValue from a signed 32-bit integer.
public static VariantValue Int32(int value)
Parameters
valueint
Returns
Int64(long)
Creates a VariantValue from a signed 64-bit integer.
public static VariantValue Int64(long value)
Parameters
valuelong
Returns
ObjectPath(ObjectPath)
Creates a VariantValue from an ObjectPath.
public static VariantValue ObjectPath(ObjectPath value)
Parameters
valueObjectPath
Returns
ReadHandle<T>()
Reads a Unix file descriptor handle for a UnixFd type.
public T ReadHandle<T>() where T : SafeHandle, new()
Returns
- T
Type Parameters
TThe SafeHandle type to read. If
Tis 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
valueSignature
Returns
String(string)
Creates a VariantValue from a string.
public static VariantValue String(string value)
Parameters
valuestring
Returns
Struct(VariantValue)
Creates a struct VariantValue with 1 field.
public static VariantValue Struct(VariantValue item1)
Parameters
item1VariantValue
Returns
Struct(VariantValue, VariantValue)
Creates a struct VariantValue with 2 fields.
public static VariantValue Struct(VariantValue item1, VariantValue item2)
Parameters
item1VariantValueitem2VariantValue
Returns
Struct(VariantValue, VariantValue, VariantValue)
Creates a struct VariantValue with 3 fields.
public static VariantValue Struct(VariantValue item1, VariantValue item2, VariantValue item3)
Parameters
item1VariantValueitem2VariantValueitem3VariantValue
Returns
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
item1VariantValueitem2VariantValueitem3VariantValueitem4VariantValue
Returns
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
item1VariantValueitem2VariantValueitem3VariantValueitem4VariantValueitem5VariantValue
Returns
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
item1VariantValueitem2VariantValueitem3VariantValueitem4VariantValueitem5VariantValueitem6VariantValue
Returns
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
item1VariantValueitem2VariantValueitem3VariantValueitem4VariantValueitem5VariantValueitem6VariantValueitem7VariantValue
Returns
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
item1VariantValueitem2VariantValueitem3VariantValueitem4VariantValueitem5VariantValueitem6VariantValueitem7VariantValueitem8VariantValue
Returns
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
item1VariantValueitem2VariantValueitem3VariantValueitem4VariantValueitem5VariantValueitem6VariantValueitem7VariantValueitem8VariantValueitem9VariantValue
Returns
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
item1VariantValueitem2VariantValueitem3VariantValueitem4VariantValueitem5VariantValueitem6VariantValueitem7VariantValueitem8VariantValueitem9VariantValueitem10VariantValue
Returns
ToString()
Returns a string representation of this variant value.
public override string ToString()
Returns
ToString(bool)
Returns a string representation of this variant value.
public string ToString(bool includeTypeSuffix)
Parameters
includeTypeSuffixboolWhether to include type information in the string.
Returns
UInt16(ushort)
Creates a VariantValue from an unsigned 16-bit integer.
public static VariantValue UInt16(ushort value)
Parameters
valueushort
Returns
UInt32(uint)
Creates a VariantValue from an unsigned 32-bit integer.
public static VariantValue UInt32(uint value)
Parameters
valueuint
Returns
UInt64(ulong)
Creates a VariantValue from an unsigned 64-bit integer.
public static VariantValue UInt64(ulong value)
Parameters
valueulong
Returns
UnixFd(SafeHandle)
Creates a VariantValue from a Unix file descriptor handle.
public static VariantValue UnixFd(SafeHandle handle)
Parameters
handleSafeHandle
Returns
Variant(VariantValue)
Wraps a VariantValue in a variant container.
public static VariantValue Variant(VariantValue value)
Parameters
valueVariantValue
Returns
Operators
operator ==(VariantValue, VariantValue)
Determines whether two VariantValue instances are equal.
public static bool operator ==(VariantValue lhs, VariantValue rhs)
Parameters
lhsVariantValuerhsVariantValue
Returns
implicit operator VariantValue(bool)
Implicitly converts a boolean value to a VariantValue.
public static implicit operator VariantValue(bool value)
Parameters
valuebool
Returns
implicit operator VariantValue(byte)
Implicitly converts a byte value to a VariantValue.
public static implicit operator VariantValue(byte value)
Parameters
valuebyte
Returns
implicit operator VariantValue(double)
Implicitly converts a double to a VariantValue.
public static implicit operator VariantValue(double value)
Parameters
valuedouble
Returns
implicit operator VariantValue(short)
Implicitly converts a signed 16-bit integer to a VariantValue.
public static implicit operator VariantValue(short value)
Parameters
valueshort
Returns
implicit operator VariantValue(int)
Implicitly converts a signed 32-bit integer to a VariantValue.
public static implicit operator VariantValue(int value)
Parameters
valueint
Returns
implicit operator VariantValue(long)
Implicitly converts a signed 64-bit integer to a VariantValue.
public static implicit operator VariantValue(long value)
Parameters
valuelong
Returns
implicit operator VariantValue(string)
Implicitly converts a string to a VariantValue.
public static implicit operator VariantValue(string value)
Parameters
valuestring
Returns
implicit operator VariantValue(ushort)
Implicitly converts an unsigned 16-bit integer to a VariantValue.
public static implicit operator VariantValue(ushort value)
Parameters
valueushort
Returns
implicit operator VariantValue(uint)
Implicitly converts an unsigned 32-bit integer to a VariantValue.
public static implicit operator VariantValue(uint value)
Parameters
valueuint
Returns
implicit operator VariantValue(ulong)
Implicitly converts an unsigned 64-bit integer to a VariantValue.
public static implicit operator VariantValue(ulong value)
Parameters
valueulong
Returns
implicit operator VariantValue(ObjectPath)
Implicitly converts an ObjectPath to a VariantValue.
public static implicit operator VariantValue(ObjectPath value)
Parameters
valueObjectPath
Returns
implicit operator VariantValue(Signature)
Implicitly converts a Signature to a VariantValue.
public static implicit operator VariantValue(Signature value)
Parameters
valueSignature
Returns
operator !=(VariantValue, VariantValue)
Determines whether two VariantValue instances are not equal.
public static bool operator !=(VariantValue lhs, VariantValue rhs)
Parameters
lhsVariantValuerhsVariantValue