本文整理汇总了C#中IScriptContext类的典型用法代码示例。如果您正苦于以下问题:C# IScriptContext类的具体用法?C# IScriptContext怎么用?C# IScriptContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IScriptContext类属于命名空间,在下文中一共展示了IScriptContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
//TODO: Refactor
public override void Evaluate(IScriptContext context)
{
if (ChildNodes.Count == 0) return;
//Create local scope
if (ShouldCreateScope)
{
IScriptScope scope = RuntimeHost.ScopeFactory.Create(ScopeTypes.Local, context.Scope);
context.CreateScope(scope);
}
try
{
int index = 0;
while (index < ChildNodes.Count)
{
var node = (ScriptAst)ChildNodes[index];
node.Evaluate(context);
if (context.IsBreak() || context.IsReturn() || context.IsContinue())
{
break;
}
index++;
}
}
finally
{
if (ShouldCreateScope)
context.RemoveLocalScope();
}
}
示例2: Evaluate
public override void Evaluate(IScriptContext context)
{
bool result = true;
if (list == null)
{
context.Result = true;
return;
}
list.Evaluate(context);
object[] rez = (object[])context.Result;
foreach (object o in rez)
{
try
{
result = result & (bool)o;
}
catch
{
throw new ScriptException("Non boolean expression in post condition");
}
}
context.Result = result;
}
示例3: Evaluate
public override void Evaluate(IScriptContext context)
{
if (context.Scope == null)
throw new ScriptExecutionException("Null scope");
context.Scope.CreateVariable(_identifier, null);
}
示例4: Evaluate
public override void Evaluate(IScriptContext context)
{
condition.Evaluate(context);
object lastResult = RuntimeHost.NullValue;
while ((bool)context.Result)
{
statement.Evaluate(context);
lastResult = context.Result;
if (context.IsBreak() || context.IsReturn())
{
context.SetBreak(false);
break;
}
if (context.IsContinue())
{
context.SetContinue(false);
}
condition.Evaluate(context);
}
context.Result = lastResult;
}
示例5: Evaluate
public override void Evaluate(IScriptContext context)
{
constrExpr.Evaluate(context);
IObjectBind call = (IObjectBind)context.Result;
context.Result = RuntimeHost.Activator.CreateInstance(context, call);
}
示例6: PyProcessContext
public PyProcessContext(IScriptContext scriptContext,
dynamic processHandler,
ProcessFactory processFactory,
string command,
string commandArguments,
string workingDirectory,
ICommandParameters commandParameters)
{
_commandParameters = commandParameters;
_scriptContext = scriptContext;
_command = command;
_commandArguments = commandArguments;
_workingDirectory = workingDirectory;
_processFactory = processFactory;
var processContext = _processFactory.CreateProcessContext(command,
commandArguments,
workingDirectory);
_processHandler = processHandler;
processContext.OnMessage += (message) =>
{
_processHandler.OnMessage(message);
// Console.WriteLine(message);
};
processContext.OnError += (message) =>
{
_processHandler.OnError(message);
};
_processHandler.OnInit(this, _commandParameters);
_processContext = processContext;
}
示例7: Invoke
public object Invoke(IScriptContext context, object[] args)
{
bool scopeOwner = false;
if (args != null)
{
if (args.Length > 1) throw new ArgumentException("Number of arguments ");
if (args.Length == 1)
{
var assigner = args[0] as ISupportAssign;
if (assigner == null) throw new NotSupportedException("Given type of argument is not supported");
assigner.AssignTo(context.CreateScope());
scopeOwner = true;
}
}
try
{
_metaProg.Evaluate(context);
return context.Result;
}
finally
{
if (scopeOwner)
context.RemoveLocalScope();
}
}
示例8: CheckPre
public void CheckPre(IScriptContext context)
{
if (!CheckCondition(pre, context))
{
throw new ScriptVerificationException("Pre condition for function call failed");
}
}
示例9: Invoke
public object Invoke(IScriptContext context, object[] args)
{
var functionScope = (INotifyingScope)RuntimeHost.ScopeFactory.Create(ScopeTypes.Function, context.Scope, context);
context.CreateScope(functionScope);
Expando values=args.FirstOrDefault() as Expando;
if (values != null) {
foreach (var field in values.Fields) {
context.SetItem(field, values[field]);
}
} else {
if (args.Length > 0)
throw new ScriptExecutionException("Wrong type of arguments passed to Program Invokation");
}
try {
Evaluate(context);
}
finally {
context.RemoveLocalScope();
context.ResetControlFlags();
}
return context.Result;
}
示例10: CheckInv
public void CheckInv(IScriptContext context)
{
if (!CheckCondition(inv, context))
{
throw new ScriptVerificationException("Invariant for function call failed");
}
}
示例11: Evaluate
public override void Evaluate(IScriptContext context)
{
// ( Expr )
if (typeExpr == null)
{
expr.Evaluate(context);
}
// (Type) Expr
else
{
typeExpr.Evaluate(context);
Type type = context.Result as Type;
if (type == null)
{
//NOTE: Handling special case of unary minus operator:
// (3+2)-2;
ScriptUnaryExpr unary = expr as ScriptUnaryExpr;
if (unary == null || unary.OperationSymbol != "-")
throw new ScriptException("Wrong type expression!");
//NOTE: expr + (unary expr)
object left = context.Result;
unary.Evaluate(context);
context.Result = @operator.Evaluate(left, context.Result);
return;
}
expr.Evaluate(context);
context.Result = RuntimeHost.Binder.ConvertTo(context.Result, type);
}
}
示例12: Invoke
public object Invoke(IScriptContext context, object[] args)
{
context.CreateScope();
context.SetItem("me", scriptable.Instance);
context.SetItem("body", scriptable);
object rez = RuntimeHost.NullValue;
try
{
rez = dynamicMethod.Invoke(context, arguments);
}
finally
{
context.RemoveLocalScope();
}
if (rez != RuntimeHost.NullValue)
{
return rez;
}
else
{
throw new ScriptException(string.Format("Dynamic method call failed in object {0}", scriptable.ToString()));
}
}
示例13: Evaluate
//TODO: reorganize switch
public override void Evaluate(IScriptContext context)
{
switch (operation)
{
case "break":
if (context.Result == null)
context.Result = RuntimeHost.NullValue;
context.SetBreak(true);
break;
case "continue":
if (context.Result == null)
context.Result = RuntimeHost.NullValue;
context.SetContinue(true);
break;
case "return":
expression.Evaluate(context);
context.SetReturn(true);
break;
case "throw":
expression.Evaluate(context);
throw (Exception)context.Result;
default:
throw new ScriptException("This should never happen");
}
}
示例14: Evaluate
public override void Evaluate(IScriptContext context)
{
_constrExpr.Evaluate(context);
var call = (IBinding)context.Result;
context.Result = RuntimeHost.Activator.CreateInstance(context, call);
}
示例15: HandleOperatorArgs
public HandleOperatorArgs(IScriptContext context, string symbol, object[] arguments)
{
Symbol = symbol;
Arguments = arguments;
Context = context;
Cancel = false;
}