惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
V
Vulnerabilities – Threatpost
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
月光博客
月光博客
T
Troy Hunt's Blog
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
P
Palo Alto Networks Blog
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
Know Your Adversary
Know Your Adversary
SecWiki News
SecWiki News
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threatpost
Forbes - Security
Forbes - Security
S
Schneier on Security
P
Proofpoint News Feed
T
Tor Project blog
Cyberwarzone
Cyberwarzone
The Hacker News
The Hacker News
Cloudbric
Cloudbric
S
Security @ Cisco Blogs
Webroot Blog
Webroot Blog
Attack and Defense Labs
Attack and Defense Labs
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
CERT Recently Published Vulnerability Notes
The Last Watchdog
The Last Watchdog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
SegmentFault 最新的问题
V
V2EX
量子位
B
Blog RSS Feed
宝玉的分享
宝玉的分享
T
The Blog of Author Tim Ferriss
罗磊的独立博客
J
Java Code Geeks

博客园 - leon qian

正则表达式全部符号解释 android显示大图片的一些技巧 SAPI 5.1 语音合成的事件 SAPI 5.1 语音合成的列举语音引擎 Unicode符号代码表 c#中的问号 读取Excel文件时出现null的解决方法 - leon qian - 博客园 让CSS区别不同浏览器 在Repeater中使用按钮或其他控件的解决方法 - leon qian - 博客园 在IIS中使用Gzip压缩后传送数据 一堆常用JS代码 stream转string,string转stream 一个XML转换的例子 JS代码整理 asp.net 真正意义上的裁减图片 由于启动用户实例的进程时出错的解决方法 C#中的正则表达式 转 SqlHelper详解(转载) [转].net用url重写URLReWriter实现任意二级域名
C#的四则运算函数 - leon qian - 博客园
leon qian · 2008-10-04 · via 博客园 - leon qian

调用:Evaluator.EvalToDouble("(512+100)/300");  
   
  using   System;  
  using   System.CodeDom.Compiler;  
  using   System.Reflection;  
  using   Microsoft.JScript;  
   
  namespace   mysoft  
  {  
        public   class   Evaluator  
        {  
              public   static   int   EvalToInteger(string   statement)  
              {  
                    string   s   =   EvalToString(statement);  
                    return   int.Parse(s.ToString());  
              }  
   
              public   static   double   EvalToDouble(string   statement)  
              {  
                    string   s   =   EvalToString(statement);  
                    return   double.Parse(s);  
              }  
   
              public   static   string   EvalToString(string   statement)  
              {  
                    object   o   =   EvalToObject(statement);  
                    return   o.ToString();  
              }  
   
              public   static   object   EvalToObject(string   statement)  
              {  
                    return   _evaluatorType.InvokeMember(  
                                            "Eval",    
                                            BindingFlags.InvokeMethod,    
                                            null,    
                                            _evaluator,    
                                            new   object[]   {   statement   }    
                                      );  
              }  
                                 
              static   Evaluator()  
              {  
                    ICodeCompiler   compiler;  
                    compiler   =   new   JScriptCodeProvider().CreateCompiler();  
   
                    CompilerParameters   parameters;  
                    parameters   =   new   CompilerParameters();  
                    parameters.GenerateInMemory   =   true;  
                     
                    CompilerResults   results;  
                    results   =   compiler.CompileAssemblyFromSource(parameters,   _jscriptSource);  
   
                    Assembly   assembly   =   results.CompiledAssembly;  
                    _evaluatorType   =   assembly.GetType("Evaluator.Evaluator");  
                     
                    _evaluator   =   Activator.CreateInstance(_evaluatorType);  
              }  
               
              private   static   object   _evaluator   =   null;  
              private   static   Type   _evaluatorType   =   null;  
              private   static   readonly   string   _jscriptSource   =    
                     
                      @"package   Evaluator  
                          {  
                                class   Evaluator  
                                {  
                                      public   function   Eval(expr   :   String)   :   String    
                                      {    
                                            return   eval(expr);    
                                      }  
                                }  
                          }";  
        }  
  }  

posted @ 2008-10-04 21:04  leon qian  阅读(2230)  评论()    收藏  举报