如何与F#Interactive交互作用测试C#
-
28-09-2019 - |
题
我有一组静态实用方法,包括单位测试。但是,我想采用一种更具交互性的方法来采用测试 - > fixing->编译周期(repl)(例如在LISP或SmallTalk中),可以在交互式模式下立即执行代码。我尝试使用F#Interactive直接从VS 2010中打开的C#项目中测试这些方法,但我没有工作。
我知道我必须加载组件(#r
指令),打开名称空间,然后可以调用方法(并检查结果)。但是,如何在Visual Studio 2010中的“ F#Interactive”中进行操作?我知道,在调试模式下可用的“立即”窗口是可能的,但是当我编写代码时,我想在“设计模式”中进行f#Interactive。
解决方案
您需要使用 #I
指令然后您可以加载组件并使用它。我编写了一个简单的C#控制台应用程序,请尝试使用此功能,然后才能正常工作。
using System;
namespace ConsoleApplication1
{
public class Program
{
static void Main(string[] args)
{
PrintMessage();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
Console.WriteLine();
}
public static void PrintMessage()
{
Console.WriteLine("MESSAGE!");
}
}
}
然后在f#Interactive中:
> #I "full path to debug directory";;
--> Added 'full path to debug directory' to library include path
> #r "ConsoleApplication1.exe";;
--> Referenced 'full path to debug directory\ConsoleApplication1.exe'
> open ConsoleApplication1;;
> Program.PrintMessage();;
MESSAGE!
val it : unit = ()
因此,它肯定有效,您只需要首先编译项目即可。只需记住重置您的会话以事先发布您的组件即可。
不隶属于 StackOverflow