Handle attributes changes

Matthieu via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 17 03:20:14 PDT 2014


Hi!

I'm trying to handle the fact that an attribute has change since
I've set it for the first time (by desialising a bson), to
abstract the only-modified fields update with vibe.d and mongodb,
without storing two times the values. The idea is to have
something like that :

class Base {
...
      // The code to handle the fact that an attribute has been
modified

      void update() {
          // Update only the fields that have been modified since
loading
      }
...
}

class A : Base {
...
      int field1;
...
}

void main() {
...
      A test = deserializeBson!A(bson);
      test.update(); // Does not updates anything

      test.field1 = 12;
      test.update(); // Now updates the 'field1' field
...
}

I've search a way to modify my methods source code at compile
time, but it seems to be impossible. So I thought that it should
be possible to rewrite the @property working, but I can't find
anything about this. Is it possible ? And if it's not, is there a
way to do what I want to do ?

Thanks!


More information about the Digitalmars-d-learn mailing list