本文整理汇总了C#中IScriptEngine.SetFunction方法的典型用法代码示例。如果您正苦于以下问题:C# IScriptEngine.SetFunction方法的具体用法?C# IScriptEngine.SetFunction怎么用?C# IScriptEngine.SetFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScriptEngine
的用法示例。
在下文中一共展示了IScriptEngine.SetFunction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Preprocess
//.........这里部分代码省略.........
}
else
{
// If at end, summarize the string
if(i == input.Length - 1)
{
// Append the last string
outputCode.Append(input[i]);
// Format output code (Replace " to ¤ and swap back on preprocessing)
String OutputCode = outputCode.ToString().Replace("\"", "¤").Replace("\n", "%BR%\");\n__printx(\"");
OutputCode = this.HandleToTokens(OutputCode.ToString(),'@');
finalOutput.Append("__printx(\"" + OutputCode + "\");");
}
try
{
if (((input[i] == '\n' && input[i + 1] == '%')) || (input[i] == '<' && input[i + 1] == '?'))
{
startCase = (input[i] == '<' && input[i + 1] == '?');
codeMode = true;
// Convert tokens to interpretable handles
String OutputCode = outputCode.ToString().Replace("\"", "¤").Replace("\n", "%BR%\");\n__printx(\"");
OutputCode = this.HandleToTokens(OutputCode.ToString(), '@');
finalOutput.Append("__printx(\"" + OutputCode + "\");");
// Clear the output code buffer
outputCode = new StringBuilder();
// Skip two tokens forward to not include those tokens to the code buffer
i += 1;
continue;
}
}
catch
{
continue;
}
outputCode.Append(input[i]);
}
}
// if exiting in text mode, append an end of the scalar string
if (!parseMode)
{
CallStack += "\");";
}
// Run the code
RuntimeMachine.SetFunction("__printx",new Func<String,object>( __printx));
RuntimeMachine.SetFunction("synchronize_data", new Func<String, object>(synchronize_data));
CallStack = finalOutput.ToString();
CallStack = CallStack.Replace("\r", "");
if (!onlyPreprocess)
{
/***
* Try run the page. If there was error return ERROR: <error> message so the
* handler can choose to present it to the user
* */
try
{
RuntimeMachine.Run(CallStack);
/**
* Check if the result of the preprocessing is the same as before. If nothing
* has changed return NONCHANGE. This is only for rendering whole pages, not inflate.
* */
if (!inflate)
{
if (Output == OldOutput)
return "NONCHANGE";
OldOutput = Output;
}
}
catch (Exception e)
{
// clear output
this.Output = "";
// Load error page
using (System.IO.StreamReader SR = new System.IO.StreamReader("views\\error.xml"))
{
string errorView = new MakoEngine().Preprocess(SR.ReadToEnd(), "", false, "", true);
RuntimeMachine = new JavaScriptEngine();
RuntimeMachine.SetFunction("__printx", new Func<String, object>(__printx));
RuntimeMachine.SetVariable("error", e.ToString() + "\n " );
RuntimeMachine.Run((errorView));
}
}
return this.Output;
}
else
{
return CallStack;
}
}