.NET scripts

Can anyone provide an example of .NET scripts?

Some dynamic languages ​​support functions such as eval()or compile(), which make it possible to compile and execute a string at run time.

VBCodeProvider seems to be a related namespace, but I cannot find an example showing how to compile and execute code.

Edit:

I am developing an ASP.NET site using VB.NET. Some behavior should be dynamic and scenario

Edit:

I think MSScriptControl is what I'm looking for ..

+3
source share
8 answers

Iron Python? . #, google 'invoke Iron Python #'. , , CodePlex, .

,.NET JavaScript, , , .

+5

Powershell. , .Net. .Net, COM WMI.

: Powershell ASP.Net , .

MSScriptControl - - VB6/COM, . IronPython.

+4

, :

NB #, VB.NET, ,

Lazy Parser

Lazy Parser .

: #, :

ParserContext context = new ParserContext();

context.AddType("Math", typeof(Math));
context.Set("SomeString", "Hi there!");
context.Set("SomeNumber", 20);
context.AddFunction("fmt",  typeof(String), "Format");

CSharpParser parser = new CSharpParser();

string stringValue = parser.Evaluate<string>("fmt(\"I said: {0}\", SomeString)", context);  // returns "I said: Hi there!"

:

// Define the context of our expression
ExpressionContext context = new ExpressionContext();
// Allow the expression to use all static public methods of System.Math
context.Imports.AddType(typeof(Math));

// Define an int variable
context.Variables["a"] = 100;

// Create a dynamic expression that evaluates to an Object
IDynamicExpression eDynamic = context.CompileDynamic("sqrt(a) + pi");
// Create a generic expression that evaluates to a double
IGenericExpression<double> eGeneric = context.CompileGeneric<double>("sqrt(a) + pi");

// Evaluate the expressions
double result = (double)eDynamic.Evaluate();
result = eGeneric.Evaluate();

// Update the value of our variable
context.Variables["a"] = 144;
// Evaluate again to get the updated result
result = eGeneric.Evaluate();

:

LUA .NET

+2

DLR ( ), , . , IronPython: http://www.voidspace.org.uk/ironpython/hosting_api.shtml, Powershell.

+2

, , .

.NET 4.0 " ", , ; PDC, "" ( ) #, REPL .

, .

+1

F # REPL .

+1

boo . python-y, IronPython. SharpDevelop.

UPDATE: Powershell, , , , , , , gui . clunkier, . - - , Windows .

0

VB.NET Flee

https://flee.codeplex.com

VB.NET:

Imports Ciloci.Flee
Imports Ciloci.Flee.CalcEngine
Imports System.Math

    Dim ec As New Ciloci.Flee.ExpressionContext
    Dim ex As IDynamicExpression
    ec.Imports.AddType(GetType(Math))

    ec.Variables("a") = 10            
    ec.Variables("b") = 40               
    ex = ec.CompileDynamic("a+b")

    Dim evalData    
    evalData = ex.Evaluate()
    Console.WriteLine(evalData)

: 50

0

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


All Articles