json2object icon indicating copy to clipboard operation
json2object copied to clipboard

Interferes with macro

Open neimanpinchas opened this issue 1 year ago • 0 comments

Hi, thanks for the wonderfull library.

I tried to use a clone macro in a class that I parse somewhere else but json2object complained, so I ended up to manually copy all fields, line by line.

I tried with @:jignored but didn't help

class Clone {
  public static macro function make_clone_code() {
    var cls = Context.getLocalClass().get().name;
    var fields = Context.getLocalClass().get().fields.get();

    var exprs:Array<Expr> = [];
    exprs.push(macro var temp=$i{"new "+cls+"()"});
    for (f in fields){
        var name=f.name;
        var expr=f.expr;
        exprs.push(macro temp.$name = $i{name});
    }
    exprs.push(macro return temp);
    // Add a clone() method to the class
    
    return macro $b{exprs}
  }
}

neimanpinchas avatar Dec 30 '24 21:12 neimanpinchas