getProperty static method

dynamic getProperty(
  1. dynamic obj,
  2. String name
)

Gets value of object property specified by its name.

  • obj an object to read property from.
  • name a name of the property to get. Returns the property value or null if property doesn't exist or introspection failed.

Implementation

static dynamic getProperty(obj, String name) {
  if (obj == null) throw Exception('Object cannot be null');
  // if (name == null) throw Exception('Property name cannot be null');

  var foundName = _findReadField(obj, name);
  if (foundName != null) {
    try {
      var im = reflect(obj);
      return im.getField(foundName).reflectee;
    } catch (e) {
      // Ignore exceptions
    }
  }

  return null;
}