How to call C # from JScript.net?

I read that for the latest Java, Java Javascript can easily call or import java packages. Can JScript.net call C # functions in latest .NET?

In more detail, I am not asking about the compiled JScript.net code, but about the uncompiled JScript.net line code that runs in the script engine.

+4
source share
2 answers

Here is an example:

1) CS file with simple calls and a method that returns a string. 2) a js file that calls the CS method using eval.

//cstest.cs - compile as a library

using System; namespace MyNamespace { public class Foo { public string Bar() { return "Hello JS"; } } } 

//test.js - compile as exe // add a link to cstest.dll // compile the jsc / t command line: exe / r: cstest.dll test.js

 import MyNamespace; var o : JSApp = new JSApp(); o.DoEval(); class JSApp { function DoEval() { var f : Foo; var s : String eval("f = new Foo;"); eval("s = f.Bar();"); // call Foo.Bar print(s); } }; 
+7
source

You need to convert JScript.NET code to C #. Something like that .

0
source

Source: https://habr.com/ru/post/1398679/


All Articles