getPropertyNames static method

List<String> getPropertyNames(
  1. dynamic obj
)

Gets names of all properties implemented in specified object.

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

Implementation

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

  var cm = reflectClass(obj.runtimeType);
  for (var dm in cm.declarations.values) {
    Symbol? foundName;

    if (dm is VariableMirror && !dm.isStatic && !dm.isPrivate) {
      foundName = dm.simpleName;
    } else if (dm is MethodMirror &&
        dm.isGetter &&
        !dm.isStatic &&
        !dm.isPrivate) foundName = dm.simpleName;

    if (foundName != null) properties.add(_extractName(foundName));
  }

  return properties;
}