什么是使用JScript.Net人呢? [英] What are people using JScript.Net for?

查看:602
本文介绍了什么是使用JScript.Net人呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道谁使用JScript.Net和什么样的应用。
每当我阅读MSDN .NET文档时,我总是看到JScript的样本,但在所有这些年来我一直在一个C#开发我从来没有真正众所周知任何人都可以使用它。

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.

什么样的​​应用程序正在使用此的人,它是如何衡量的,在灵活性,力量和一般使用条款,以C#?

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

[修改只是为了澄清 - 我不要求什么JScript.Net的的,我在问什么人真正使用它 - 即兴趣知道实际的使用场景和人们如何发现它一起工作]

[ 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]

推荐答案

罗布 - 我在code,这基本上是暴露其eval方法的功能使用JScript.NET愤怒在一个地方。这里是一个简化版本:

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;
        }
    }

您可以明显为其他返回类型的重载。我不能要求这样做的最初的想法是我的!用途这将是,例如,评估一个字符串的前pression像 3 + 4 7 没有前pression解析。

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.

这篇关于什么是使用JScript.Net人呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆