开发者

Can I access types created in F# Interactive with System.CodeDom?

开发者 https://www.devze.com 2023-02-27 11:03 出处:网络
I am creating my type in FSX and passing those types into the Razor templating engine with the open source RazorEngine project.

I am creating my type in FSX and passing those types into the Razor templating engine with the open source RazorEngine project.

Hosting Razor outside of ASP.NET requires compiling the Razor templates. If I pass a model created in FSX into the template, will System.CodeDom be able to have access to that type created by FSI? The basic error tha开发者_开发知识库t I get is "The type or namespace name 'FSI_0004' could not be found".


Code that's compiled using System.CodeDom cannot generally have access to the code loaded in F# Interactive - the CodeDom essentially writes the C#/F# source code to disk and then invokes the command line compiler on the code (and the command line compiler cannot reference code loaded in F# Interactive).

There may be a way to get it working though - You could use the F# CodeDom provider from PowerPack. You could modify it to generate the source code (as it currently does) and then send the generated code to F# Interactive (instead of invoking command line compiler). This way, the code compiled on-the-fly could see F# Interactive code.

There are some issues that need to be resolved

  • Is it possible to provide your own CodeDom provider to RazorEngine?
  • The F# CodeDom provider may not correctly handle code generated by Razor (so you may need to fix/workaround a few things in the F# CodeDom provider). You may also need to modify it to generate code that works nicely with F# interactive (e.g. remove top-level namespaces)
  • What instance of F# Interactive do you want to use? (And how to get standard input, so that you can send your code there)
  • Do you need to load the compiled assembly and pass it back to Razor? I'm not sure if this can be done with F# Interactive.

These all depend on your scenario - but I guess that it may be possible to get what you want (possibly with some workarounds).

0

精彩评论

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

关注公众号