public void Testpad() { var evaluator = lib::CSScriptLib.CSScript.Evaluator; ICodeVariable script = evaluator.ReferenceAssemblyOf <ICodeVariable>() .LoadCode <ICodeVariable>(@" using System; public class Test : ICodeVariable { public object Evaluate(){ return ""Hello World""; } }"); var x = script.Evaluate(); }
private static ICodeVariable GetScriptObject(string sourceCode) { if (string.IsNullOrWhiteSpace(sourceCode)) { throw new ArgumentException("SourceCode is empty"); } string md5Key = CalculateMD5Hash(sourceCode); if (scriptObjects.ContainsKey(md5Key)) { return(scriptObjects[md5Key] as ICodeVariable); } CSScript.EvaluatorConfig.RefernceDomainAsemblies = true; ICodeVariable scriptObject = CSScript.Evaluator.LoadCode <ICodeVariable>(sourceCode); scriptObjects[md5Key] = scriptObject; return(scriptObject); }
public static void Compile(string sourceCode) { ICodeVariable script = GetScriptObject(sourceCode); }
public static object Evaluate(string sourceCode, BaseErpPageModel pageModel) { ICodeVariable script = GetScriptObject(sourceCode); return(script.Evaluate(pageModel)); }