J
Jelle van Baardewijk
Does anybody know if there's way to do this in C#?
Jelle van Baardewijk
Jelle van Baardewijk
Jelle van Baardewijk said:Does anybody know if there's way to do this in C#?
What is "callbyname" ?
Garrett said:Call by name has to do with the way arguments
are passed, not calling a method by it's name.
See for example:
http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?call-by-name
Patrick Steele said:It's from VB6. It allows you to execute methods on an object based on
the "name" of the method. It's basically late-binding, but the method
name may not be known at design-time. The code determines the method to
call and uses the CallByName function to dynamically make the call.
Yeah, thanks, it seems that reflection can handle this sort of things, right?
Patrick said:Yup!
Carsten Posingies said:Just for couriousity, could you point me to an example in C#?
Jon said:Carsten Posingies said:Just for couriousity, could you point me to an example in C#?
Yup:
MethodInfo method = typeof(Test).GetMethod("PrintGreeting");
method.Invoke (t, new object[]{"Carsten"});
Carsten Posingies said:Jon said:Carsten Posingies said:Just for couriousity, could you point me to an example in C#?
Yup:
MethodInfo method = typeof(Test).GetMethod("PrintGreeting");
method.Invoke (t, new object[]{"Carsten"});
Argh! *blush* Same as one can call a JScript's method from within C#
code when tampering with the script engine.
If there was a way to "compound" GetMethod() and Invoke(), we would have
had something similar to JScript's eval()... If there wasn't the word
"if"... <g>
Thanks!