Call method with Variant array as parameters

Andre Pany andre at s-e-a-p.de
Sat Jul 14 11:08:21 UTC 2018


Hi,

I have a class with methods and I want to call a method by using 
a variant array.
The length of the array and the types exactly fits the method 
signature.

In the last line of main you see the coding which should be 
generated.
I need some coding which looks at the signature of bar and uses 
this information
to create "(args[0].get!string, args[1].get!long)".

I think it is possible with string mixins, but is there some 
better way?
Maybe a staticMap?

class Foo
{
     void bar(string s, long l) {}
}

void main()
{
     import std.variant: Variant;

     Foo foo = new Foo();

     Variant[] args = [Variant("Hello"), Variant(42)];
     __traits(getMember, foo, "bar")(args[0].get!string, 
args[1].get!long);
}

Kind regards
André


More information about the Digitalmars-d-learn mailing list