在C#中运行的F#代码 - (如C#在C#中使用罗斯林)

问题描述:

有没有办法在C#中运行F#代码?我已经用C#编写的应用程序 - 我想提供它从F#执行F#,读取记录对象,列举名单的能力。什么是这个当前的解决方案?我知道,在未来将有可能是一个办法通过一个更新罗斯林做到这一点。另外,好奇如何在F#中运行的F#代码,当前。有没有办法做到这一点容易吗?

Is there a way to run F# code in C#? I have written an app in C# - I'd like to provide it the ability to execute F#, read Record objects, enumerate lists from F#. What is the current solution for this? I know in the future there will be probably be a way to do this via an update to Roslyn. Also, curious how to run F# code in F#, currently. Is there a way to do that easily?

目前,你必须使F#库,然后从调用它C#。由于F#是.NET仅仅使用F#库(大部分)就像使用任何其他C#库。你可能想看看 FSharpX 这个部分,但是,由于它提供了一些实用工具,以缓解从调用C#F#,反之亦然。

Currently, you have to make the F# a library, and then call it from C#. Since F# is just .NET, using the F# library is (mostly) just like using any other C# library. You might want to look into FSharpX for this portion, however, as it provides some utilities to ease calling F# from C# and vice versa.

如果您想从动态C#编译F#,你需要使用F#的CodeDOM实现从的 F#电源包的。这将让你使用的CodeDOM编译飞F#,然后从C#执行它。

If you want to compile the F# dynamically from C#, you'll need to use the F# CodeDom implementation from the F# Power Pack. This will let you use CodeDom to compile F# on the fly, and then execute it from C#.

请注意,罗斯林不会有所帮助,甚至当它的发布,因为它不支持F#作为代码模型中,只有C#和VB.Net。这将潜在地可能使用罗斯林操纵和选自F#内编译C#,而不是周围的其他方法

Note that Roslyn will not help here, even when it's released, as it won't support F# as a code model, only C# and VB.Net. It would potentially be possible to use Roslyn to manipulate and compile C# from within F#, but not the other way around.