使用C#作为我的DSL - 这是可能的,如果是这样,怎么样? [英] Using C# as my DSL -- is this possible, if so, how?

查看:1507
本文介绍了使用C#作为我的DSL - 这是可能的,如果是这样,怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用C#作为DSL 在C#源代码是由最终用户在TextBox编辑,应用程序运行时通过已经运行的应用程序编译,然后叫?

Is it possible to use C# as a DSL in which the C# source code is edited by the end user in a TextBox, compiled while the application is running, then called by the already-running application?

我问,因为在我将需要实现一个简单的数学运算DSL(类似的财产以后雷切尔林的博客上讲述在的 http://rachel53461.wordpress.com/2011/08/20/the-math-converter /
我专注于她的代码,而不是XAML /转换器方面)的数学处理方面。我靠在只是重用她的代码,因为我想补充if语句和其他可能的功能。如果我可以使用C#语言本身,然后我得到的所有功能,而无需重新实现它们。

I ask because in the next few months I will be needing to implement a simple math-crunching DSL (similar to somthing Rachel Lim blogged about at http://rachel53461.wordpress.com/2011/08/20/the-math-converter/ I am focused on the math-processing aspect of her code, not the XAML/Converter aspect). I would lean against just reusing her code because I want to add if-statements and possibly other features. If I can use C# itself, then I get all of the features without having to re-implement them.

如果有可能做到这一点,什么框架或命名空间或类我想使用完成这样?

If it is possible to do this, what framework or namespace or class would I want to use to accomplish such?

请注意,有一件事我会用C#做衍生DSL是硬编码一切必要使用头部语句,然后删除所有using语句被精明的用户输入。这样做的目的是为了减少最终用户试图利用我的C#般的DSL到对他们企业的政策或没有站点管理员的知识的愿望有一个全面的编译器的前景。 是我所提出的using语句足够的防御用户恶作剧的管理?

Please note that one thing I would do with the C#-derived DSL is hard-code all necessary using header statements, then remove all using statements entered by the savvy user. The purpose of this is to reduce the prospect of an end user trying to leverage my C#-like DSL into a full-fledged compiler against the wishes of their enterprise policy or without the knowledge of the site administrator. Is my proposed managing of using statements an adequate defense against user mischief?

最后,如果所有的答案到这一点是是,然后点击什么是这种方法的弊端,尤其是引入的一个安全漏洞的缺点?

Finally, if all of the answers up to this point are "yes", then what are the drawbacks of this approach, especially drawbacks of introducing a security vulnerability?

推荐答案

自动#1转换现在链接答案评论。多么可爱。

Stackoverflow automatically converts link answers to comments now. How lovely.

编译并运行动态代码,而不生成EXE?

总之,答案在于 Microsoft.CSharp.CSharpCodeProvider

这篇关于使用C#作为我的DSL - 这是可能的,如果是这样,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆