Re: comunication between JScript and C#
- From: "Ben Voigt" <rbv@xxxxxxxxxxxxx>
- Date: Thu, 11 Jan 2007 10:58:59 -0600
"bowser" <alessandro.denardi@xxxxxxxxx> wrote in message
news:1168530340.308915.291510@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,
I have a problem of communication between JScript and C#. I must say
that I'm new to both.
In a JS file I have to call a C# function.
In particular I have:
public function Eval(expr : String) : String
{
return eval(expr);
}
That's not JavaScript/JScript/ECMAScript/whaddevayacallit... are you using
JScript.NET? JScript.NET should be able to call directly into any .NET
Assembly.
And I want to call:
Eval("MyNS.myFunction()");
where myFunction is declared in a C# file, under the namespace MyNS,
and returns a string.
Err, C# functions can't be loose in a namespace. You need a class name in
there somewhere.
Is it possible to do such a thing without to consider COM objects
(which I've heard to be used in similar problems)?
Note that the .js file is generated dinamically by a CodeDomProvider in
C#.
It is compiled by adding the reference of the .exe file, which contains
myfunction():
parameters.ReferencedAssemblies.Add("MyApp.exe");
So the call Eval("MyNS.myFunction()"); will be done with Reflection
If you have a metadata reference, why use Eval at all? With a reference the
JScript.NET compiler knows about MyNS and you can directly do:
var result = MyNS.MyClass.myFunction();
with no eval call
One more question: is there another way to use the jscript function
eval in C#? Maybe compiling a .js module (not dinamically and not using
reflection) that can be used by a C# module?
There's Microsoft.JScript.Eval.JScriptEvaluate method, but documentation is
really bad. You'd have to disassemble it to find out if it's useful to you.
Thank you.
Alessandro
.
- References:
- comunication between JScript and C#
- From: bowser
- comunication between JScript and C#
- Prev by Date: Parameter Passing from C# to C++
- Next by Date: Re: Parameter Passing from C# to C++
- Previous by thread: Re: comunication between JScript and C#
- Next by thread: Re: comunication between JScript and C#
- Index(es):
Relevant Pages
|