使用 IronPython 从 python 字符串中获取 CodeExpression?
我正在尝试从 python 字符串中获取 CodeExpression。这似乎是可能的,因为一些 DLR 文档提到了 CodeDom 类,但我无法找到任何示例或更好的文档。任何见解或伪代码表示赞赏...
仅供参考,这里的用例是制作一个可以评估Python以在SharePoint 2010中使用的Asp.Net ExpressionBuilder。让我知道是否有类似的东西!
I'm trying to get a CodeExpression from a string of python. It seems possible since some of the DLR docs mention CodeDom classes but I haven't been able to find any examples or better docs. Any insight or psuedocode appreciated...
FYI, the use case here is to make an Asp.Net ExpressionBuilder that can evaluate python to use in SharePoint 2010. Let me know if there's anything like this out there!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IronPython 1.0 和 1.1 中有一个 CodeDom 提供程序,但从未移植到 2.x。部分问题在于 CodeDom 模型不能很好地与 Python 配合使用,因为 CodeDom 经常被用来(尤其是 ASP.NET)来创建代码、编译代码,然后加载生成的程序集并从中获取某些类型。它。最后一点很难在语言中做出一些妥协。但在 1.x 中,我们对此进行了尝试,CodeDom 提供程序可以编译为可以加载的类 - 基本的 ASP.NET 示例可以工作。所以你可以尝试一下。
我想知道您是否可以在执行代码时创建一个 C# CodeExpression?例如 scriptEngine.Execute(“代码字符串”)?如果您的表达式可以引用页面上声明的其他变量,那么这将起作用 - 您在某处实例化页面(或使其静态),然后只需构建一个通过托管 API 运行代码的 CodeExpression。
There was a CodeDom provider in IronPython 1.0 and 1.1 but it was never ported to 2.x. Part of the problem is that the CodeDom model doesn't work very well with Python because CodeDom is frequently used (and in particular by ASP.NET) to create code, compile it, and then load the resulting assembly and get some types out of it. That last bit is hard to provide w/o some compromises in the language. But in 1.x we played around with this and the CodeDom provider can compile to classes which can be loaded - basic ASP.NET samples worked. So you could give that a shot.
I wonder if you could make a C# CodeExpression when executes the code instead? For example scriptEngine.Execute("code string")? This would work if your expression could refer to other variables declared on the page - you instantiate the page somewhere (or make it static) and then just build a CodeExpression which runs the code via the hosting APIs.