NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 17543|回复: 12
打印 上一主题 下一主题

[VB & C#] grasshopper动态编译

[复制链接]
跳转到指定楼层
1m
发表于 2011-2-12 03:44:56 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 panhao1 于 2011-2-12 03:47 编辑

简单点说就是把字符串当代码使用    和vb编辑器功能一样

这里我输入了一个计算式 编译这段代码 然后用messagebox(文本框)显示计算结果
如果掌握了这段代码的精髓 就可以自己做参数化小工具

string S = "using System;namespace Application{class App{public static void Main(string[] args){System.Windows.Forms.MessageBox.Show((";
    S += x;
    S += ").ToString());}}}";
    string objectExecutive = "F:/test.exe";
    System.CodeDom.Compiler.CompilerParameters compilerParameters = new System.CodeDom.Compiler.CompilerParameters();
    compilerParameters.GenerateExecutable = true;
    compilerParameters.OutputAssembly = objectExecutive;
    compilerParameters.IncludeDebugInformation = true;
    compilerParameters.GenerateInMemory = false;
    compilerParameters.TreatWarningsAsErrors = false;
    System.CodeDom.Compiler.CompilerResults compilerResults = null;

    compilerResults = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp").CompileAssemblyFromSource(compilerParameters, S);

思路为生成exe或是dll 然后加载
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
2m
 楼主| 发表于 2011-2-12 03:50:13 | 显示全部楼层
不要尝试加载system.dll否者会报错
代码无非是多几截 嫌麻烦的话直接用VS2010好啦

小黑屋|手机版|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 )    辽公网安备21021102000973号

GMT+8, 2024-6-1 11:01 , Processed in 0.314999 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表