例如类Value 
Value.A=1
Value.B=5 
Value.C=10 
数据库中取出的运算公式串为
(A=1) and (B>2) and (C<6)
怎么样替代算出逻辑值来
。。

解决方案 »

  1.   

    找到了一个
     public class Eval
        {
            public static object GetValue(string value)
            {
                string codeSnippet = "using System; " + "\r\n" +
                "namespace CzG {" + "\r\n" +
                " public class Eval" + "\r\n" +
                " {" + "\r\n" +
                " public Eval(){} " + "\r\n" +
                " public object GetValue()" + "\r\n" +
                " {" + "\r\n" +
                " return " + value + ";" + "\r\n" +
                " }" + "\r\n" +
                " } }";
                CodeSnippetCompileUnit unit = new CodeSnippetCompileUnit(codeSnippet);
                ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();
                CompilerParameters para = new CompilerParameters();
                para.ReferencedAssemblies.Add("System.dll");
                para.GenerateInMemory = true;
                para.GenerateExecutable = false;
                para.OutputAssembly = "Eval.dll";            Assembly asm = compiler.CompileAssemblyFromDom(para, unit).CompiledAssembly;            Type type = asm.GetType("CzG.Eval");
                MethodInfo mi = type.GetMethod("GetValue", BindingFlags.Public | BindingFlags.Instance);            object obj = asm.CreateInstance("CzG.Eval");
                return mi.Invoke(obj, null);
            }
        }
               bool a= Convert.ToBoolean(Eval.GetValue("125<23" ));
      

  2.   

    是这个意思?
    (Value.A==1)& (Value.B>2) & (ValueC <6) 
      

  3.   

    将1,2,6作为类初始化时的参数new Value(1,2,6),如果要加入逻辑符号的话,就改为new Value(1,2,6,sya,syb,syc)将A B C换为属性,在赋值的时候可以判断是否符合条件