Reference of Getter/Setter functions

dart

Solution

In short, you don't. Getters and setters are not extractable - they are indistinguishable from just having a field (if you don't do side-effects, of course).

In your example, you could just do:

class Actor {
  int x;
} 

and get exactly the same effect.

What you want is, for some Actor "actor", to make the functions yourself:

var item = new PropertyItem(() => actor.x, (v) { actor.x = v; });

This proposal about generalized tear offs is approved and will probably implemented soon and allows to closurize getters and setters like:

var item = new PropertyItem(actor#x, actor#x=);

Problem

I have the following variable and getter / setter defined in my data model: ``` class Actor { int _x; int get x => _x; set x(int value) => _x = value; } ``` And there is this generic class that requires a getter / setter function pointer ``` class PropertyItem { var getterFunction; var setterFunction; PropertyItem(this.getterFunction, this.setterFunction); } ``` How do i pass a reference of the getter / setter function of X to the PropertyItem class? ``` // Something like this var item = new PropertyItem(x.getter, x.setter); ``` EDIT: Updated with a more clear question

Original source