public readonly struct DBusValue : IEquatable<DBusValue> One D-Bus value with its type signature: a basic value, a variant, an array, a dictionary or a structure.
Remarks
Create values with the static factories, such as DBusValue.From or DBusValue.Array, and read them with the matching getter, such as DBusValue.GetString. A getter for another type throws InvalidOperationException. Values compare by signature and content. A h value carries a file descriptor: one received in a message is a SafeFileHandle that belongs to the receiver, which disposes it. The default value has an empty signature and holds nothing.
Properties
IsDefault
public bool IsDefault { get; } Whether this is the default value, which holds nothing.
Remarks
An empty container, such as an as without items, is not the default value.
Signature
public DBusSignature Signature { get; } The value's type, one complete type such as s or a{sv}; empty for the default value.
Methods
Array
public static DBusValue Array(DBusSignature elementSignature, IEnumerable<DBusValue> items) Creates an array of elementSignature values, such as as for strings.
Exceptions
ArgumentExceptionThe element signature is not one complete type, or an item has another signature.
ByteArray
public static DBusValue ByteArray(ReadOnlySpan<byte> items) Creates an ay value.
Remarks
The value keeps the bytes as one block, so a large ay costs about its length in memory.
Dictionary
public static DBusValue Dictionary(DBusSignature keySignature, DBusSignature valueSignature, IEnumerable<KeyValuePair<DBusValue, DBusValue>> entries) Creates a dictionary, such as a{sv}, from entries whose keys have a basic type.
Exceptions
ArgumentExceptionThe key signature is not a basic type, the value signature is not one complete type, an entry has other signatures, or a key repeats.
From
public static DBusValue From(string value) From
public static DBusValue From(DBusSignature value) Creates a g value, a signature carried as data.
GetBoolean
public bool GetBoolean() Gets a b value.
GetByte
public byte GetByte() Gets a y value.
GetByteArray
public ImmutableArray<byte> GetByteArray() Gets the bytes of an ay value.
Remarks
The bytes are the value's own, not a copy.
GetDouble
public double GetDouble() Gets a d value.
GetEntries
public ImmutableArray<KeyValuePair<DBusValue, DBusValue>> GetEntries() Gets the entries of a dictionary, in message order.
Remarks
A dictionary received in a message keeps every entry, including one whose key repeats an earlier key.
GetInt16
public short GetInt16() Gets an n value.
GetInt32
public int GetInt32() Gets an i value.
GetInt64
public long GetInt64() Gets an x value.
GetItems
public ImmutableArray<DBusValue> GetItems() Gets the items of an array that is not a dictionary.
Remarks
For an ay, DBusValue.GetByteArray reads the bytes without creating a value for each.
GetObjectPathArray
public ImmutableArray<DBusObjectPath> GetObjectPathArray() Gets the paths of an ao value.
GetString
public string GetString() Gets an s value.
GetUInt16
public ushort GetUInt16() Gets a q value.
GetUInt32
public uint GetUInt32() Gets a u value.
GetUInt64
public ulong GetUInt64() Gets a t value.
GetUnixFd
public SafeHandle GetUnixFd() Gets the file descriptor of an h value. A received descriptor belongs to the caller, which disposes it.
Remarks
A descriptor received in a message is a SafeFileHandle, so it can be cast and wrapped in a FileStream; a value created with DBusValue.UnixFd returns the handle it was created with.
GetVariantDictionary
public ImmutableDictionary<string, DBusValue> GetVariantDictionary() Gets an a{sv} value as a dictionary of the values inside its variants.
Remarks
D-Bus does not forbid a peer from repeating a key. When a key repeats, the last entry's value wins, as in GLib's GVariantDict and GDBusProxy and in dbus-python; DBusValue.GetEntries still lists every entry.
ObjectPathArray
public static DBusValue ObjectPathArray(IEnumerable<DBusObjectPath> items) Creates an ao value.
Struct
public static DBusValue Struct(params ReadOnlySpan<DBusValue> fields) Creates a structure of one or more fields, such as (si).
Exceptions
ArgumentExceptionThere are no fields, or a field is the default value.
ToString
public override string ToString() Formats the value for logs, such as {'Volume': <0.5>}.
UnixFd
public static DBusValue UnixFd(SafeHandle value) Creates an h value that sends a file descriptor. The caller keeps ownership of the handle.
Exceptions
ArgumentExceptionThe handle is invalid or closed.
VariantDictionary
public static DBusValue VariantDictionary(IEnumerable<KeyValuePair<string, DBusValue>> entries) Creates an a{sv} value, wrapping each value in a variant.
Exceptions
ArgumentExceptionA value is the default value, or a key repeats.