Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are people using JScript.Net for?

I'm interested to know who uses JScript.Net and for what sort of applications. Whenever I'm reading MSDN .Net documentation, I always notice the JScript samples but in all the years I've been a C# dev I've never actually known anyone to use it.

What sort of applications are people using this for, and how does it measure, in terms of flexibility, power and general usage, to C#?

[Edit: Just to clarify - I'm not asking what JScript.Net is, I'm asking what people are actually using it for - i.e. interested to know actual usage scenarios and how people have found it to work with]

like image 695
Rob Levine Avatar asked Dec 13 '09 13:12

Rob Levine


People also ask

Does JScript exist?

JScript was first supported in the Internet Explorer 3.0 browser released in August 1996. Its most recent version is JScript 9.0, included in Internet Explorer 9.

What is the difference between JavaScript and JScript?

It is a trademark scripting language specification. JScript released in 1996 by Microsoft, as Microsoft's dialect of ECMAScript. JScript and JavaScript are different names for the same language. They have different names to avoid trademark issues.

Is C# based on JScript?

To be clear, C# was a proposed JavaScript alternative that could be used exclusively for Microsoft software. Since C# is the programming language of the most popular software on the planet, it has gone through many versions and updates.

Is JavaScript .NET language?

NET is a . NET programming language developed by Microsoft.


1 Answers

Rob - I have used JScript.NET in anger in one place in my code, which is essentially to expose the functionality of its eval method. Here is a cut-down version:

static public class Evaluator {     private const string _jscriptSource =         @"package Evaluator         {            class Evaluator            {               public function Eval(expr : String) : String                {                   return eval(expr);                }            }         }";      static private object _evaluator;     static private Type _evaluatorType;      static Evaluator()     {         InstantiateInternalEvaluator();     }      static private void InstantiateInternalEvaluator()     {         JScriptCodeProvider compiler = new JScriptCodeProvider();          CompilerParameters parameters;         parameters = new CompilerParameters();         parameters.GenerateInMemory = true;          CompilerResults results;         results = compiler.CompileAssemblyFromSource(parameters, _jscriptSource);          Assembly assembly = results.CompiledAssembly;         _evaluatorType = assembly.GetType("Evaluator.Evaluator");          _evaluator = Activator.CreateInstance(_evaluatorType);     }      static public object EvaluateToObject(string statement)     {         try         {             return _evaluatorType.InvokeMember(                 "Eval",                 BindingFlags.InvokeMethod,                 null,                 _evaluator,                 new object[] {statement}                 );         }         catch (Exception)         {             InstantiateInternalEvaluator();             return null;         }     } 

You can obviously create overloads for other return types. I can't claim the original idea for this was mine! Uses for this would be, for example, to evaluate a string expression like 3 + 4 to 7 without expression parsing.

like image 139
David M Avatar answered Sep 21 '22 23:09

David M