getPropertyNames static method

List<String> getPropertyNames(
  1. dynamic obj
)

Gets names of all properties implemented in specified object.

The object can be a user defined object, map or array. Returned property name correspondently are object properties, map keys or array indexes.

  • obj an objec to introspect. Returns a list with property names.

Implementation

static List<String> getPropertyNames(obj) {
  var properties = <String>[];

  if (obj is IValueWrapper) obj = obj.innerValue();

  if (obj == null) {
    // Do nothing
  } else if (obj is Map) {
    for (var key in obj.keys) {
      properties.add(key.toString());
    }
  } else if (obj is List) {
    for (var index = 0; index < obj.length; index++) {
      properties.add(index.toString());
    }
  } else {
    properties = PropertyReflector.getPropertyNames(obj);
  }

  return properties;
}