Beispiel #1
0
 public Evaluator(EvaluatorItem item)
 {
     EvaluatorItem[] items = { item };
       ConstructEvaluator(items);
 }
Beispiel #2
0
        private void ConstructEvaluator(EvaluatorItem[] items)
        {
            ICodeCompiler comp = (new CSharpCodeProvider().CreateCompiler());
              CompilerParameters cp = new CompilerParameters();
              cp.ReferencedAssemblies.Add("system.dll");
              cp.ReferencedAssemblies.Add("system.data.dll");
              cp.ReferencedAssemblies.Add("system.xml.dll");
              cp.GenerateExecutable = false;
              cp.GenerateInMemory = true;

              StringBuilder code = new StringBuilder();
              code.Append("using System; \n");
              code.Append("using System.Data; \n");
              code.Append("using System.Data.SqlClient; \n");
              code.Append("using System.Data.OleDb; \n");
              code.Append("using System.Xml; \n");
              code.Append("namespace ADOGuy { \n");
              code.Append("  public class _Evaluator { \n");
              foreach(EvaluatorItem item in items)
              {
            code.AppendFormat("    public {0} {1}() ",
                          item.ReturnType.Name,
                          item.Name);
            code.Append("{ ");
            code.AppendFormat("      return ({0}); ", item.Expression);
            code.Append("}\n");
              }
              code.Append("} }");

              CompilerResults cr = comp.CompileAssemblyFromSource(cp, code.ToString());
              if (cr.Errors.HasErrors)
              {
            StringBuilder error = new StringBuilder();
            error.Append("Error Compiling Expression: ");
            foreach (CompilerError err in cr.Errors)
            {
              error.AppendFormat("{0}\n", err.ErrorText);
            }
            throw new Exception("Error Compiling Expression: " + error.ToString());
              }
              Assembly a = cr.CompiledAssembly;
              _Compiled = a.CreateInstance("ADOGuy._Evaluator");
        }
Beispiel #3
0
 public Evaluator(EvaluatorItem[] items)
 {
     ConstructEvaluator(items);
 }