开发者

Get CodeExpression from string of python using IronPython?

开发者 https://www.devze.com 2023-02-14 11:01 出处:网络
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 insigh

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 insigh开发者_如何学Ct 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消