Get CodeExpression from string of python using IronPython?
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.
精彩评论