示例#1
0
    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();
    }
示例#2
0
        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);
        }
示例#3
0
 public static void Compile(string sourceCode)
 {
     ICodeVariable script = GetScriptObject(sourceCode);
 }
示例#4
0
        public static object Evaluate(string sourceCode, BaseErpPageModel pageModel)
        {
            ICodeVariable script = GetScriptObject(sourceCode);

            return(script.Evaluate(pageModel));
        }