使用 IronPython 从 python 字符串中获取 CodeExpression?

发布于 2024-10-19 21:55:33 字数 202 浏览 5 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山有枢 2024-10-26 21:55:33

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文