Re: comunication between JScript and C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"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



.



Relevant Pages

  • Re: Efficiently passing strings?
    ... > I'm instantiating the same string object twice (once for the parameter ... first is probably fine after optimization. ... compiler; there's really no other way to tell. ... using a reference exposes some of your implementation. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Multiple Inheritance with Interfaces
    ... I cast one to the Interface it compiled, ... it compiles ok only because the java compiler does not ... It is very hard for a compiler to determine what to do in this case, because a carefully timed thread could plant a String into mumble between line 1 and line 2, allowing line 2 to execute without error. ... but with reference expression treated as being capable of referencing ...
    (comp.lang.java.programmer)
  • Re: Object reference not set to an instance of an object
    ... TObject" you're declaring a reference to an instance of TObject. ... The compiler can't know what ... The Y TObject variable is just a reference to an object. ... In the Win32 personality of Delphi, that new string is actually a nil ...
    (alt.comp.lang.borland-delphi)
  • Re: Array of strings
    ... > pointers to the same constant string. ... When you assign the literal to s, the compiler calls LStrLAsg. ... perform any reference counting on the source string. ...
    (comp.lang.pascal.delphi.misc)
  • Re: string compare problem
    ... > String objects are references to the actual strings. ... to compare String objects, you are comparing addresses, not the contents ... [JScript] ... A String or a null reference. ...
    (microsoft.public.dotnet.languages.csharp)