Peter Uithoven
Peter Uithoven

Reputation: 825

Dynamically access property using variable

How does one retrieve a property from an object when the name of that property name is a variable?

Simply using the following doesn't seem to work

object[prop_name]

In this case it's to dynamically retrieve a value from a GLib.Object after it changed:

device.notify[prop_name].connect((s, p) => {
   debug ("  updated: %s", device[prop_name]);
});

Upvotes: 2

Views: 105

Answers (1)

Peter Uithoven
Peter Uithoven

Reputation: 825

The following seems to work

string value;
device.get (prop_name, out value);
debug ("  update: %s", value);

Upvotes: 3

Related Questions