I have a struct created by thrift:

struct Card {
  long id;
  string pwd;
  long agentId;
  bool valid;
  long rmb;
  long createDate;
  long soldDate;
  long chargeDate;

  mixin TStructHelpers!([
    TFieldMeta(`id`, 1, TReq.OPTIONAL),
    TFieldMeta(`pwd`, 2, TReq.OPTIONAL),
    TFieldMeta(`agentId`, 3, TReq.OPTIONAL),
    TFieldMeta(`valid`, 4, TReq.OPTIONAL),
    TFieldMeta(`rmb`, 5, TReq.OPTIONAL),
    TFieldMeta(`createDate`, 6, TReq.OPTIONAL),
    TFieldMeta(`soldDate`, 7, TReq.OPTIONAL),
    TFieldMeta(`chargeDate`, 8, TReq.OPTIONAL)
  ]);
}

and another class created for hibernated:

class Card
{
        import hibernated.core;

        @Id
        @Generated
        long id;
        @UniqueKey
        string pwd;
        //index
        long agentId;
        bool valid;
        long rmb;
        long createDate;
        long soldDate;
        long chargeDate;
}


Sometime , I need to copy them:

thrift.Card tc;
....
db.Card dc;

dc.id = tc.id;
dc.pwd = tc.pwd;
...


It is boring coding, I want a solution to copy them automatically:
void copyObj(SRC,DEST)(SRC src,DEST dest)
{
        foreach (i, type; typeof(SRC.tupleof)) {
                auto name = SRC.tupleof[i].stringof;
__traits(getMember, dest, name) = __traits(getMember, src, name);
                writeln(name);
        }
}

Unfortunitely, it doesnt work,  how to improve it?

Any suggestions is welcome.
Thx ahead!!!

Reply via email to