|
|
|
Re: Using reflection [message #1820562 is a reply to message #1820551] |
Wed, 22 January 2020 21:32 |
|
Hi Ludovico,
Below is a terrible solution for calling operations reflectively.
var s = "";
s.call("foo").println();
s.call("bar").println();
operation String foo() : String {
return "foo";
}
operation String bar() : String {
return "bar";
}
operation Any call(op : String) : Any {
var m = new Native("org.eclipse.epsilon.eol.EolModule");
m.parse("return target." + op + "();");
m.operations.addAll(System.context.module.operations);
m.context.frameStack.put("target", self);
return m.execute();
}
Cheers,
Dimitris
|
|
|
Re: Using reflection [message #1820563 is a reply to message #1820562] |
Wed, 22 January 2020 21:41 |
|
... and below is a more decent solution.
var s = "";
s.call("foo").println();
s.call("bar").println();
operation String foo() : String {
return "foo";
}
operation String bar() : String {
return "bar";
}
operation Any call(op : String) : Any {
return System.context.module.
operations.selectOne(o|o.name = op).
execute(self, /*parameters*/ Sequence{}, System.context);
}
Cheers,
Dimitris
|
|
|
|
Re: Using reflection [message #1820657 is a reply to message #1820587] |
Sat, 25 January 2020 09:29 |
|
Hi Sina,
If we want to add proper built-in support for calling operations reflectively I guess we should also check argument types, consider operation contributors, dot vs. arrow etc.
Cheers,
Dimitris
|
|
|
|
Re: Using reflection [message #1820728 is a reply to message #1820671] |
Mon, 27 January 2020 20:52 |
|
Hi Sina,
Given that there's a sensible workaround, I'd be inclined to wait for a couple of similar use-cases to show up before we consider implementing this feature.
Cheers,
Dimitris
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05141 seconds