Can I use F # Interactive for a script or interactively debug / test my C # GUI projects?

I saw a demo of F # and DirectX.

The user selects a piece of F # code and sends it to F # interactive. It is between them, the form flow works: the form displays dynamic content and responds to clicks.

Can I conclude that for an existing C # winforms project, I can create an F # project that references it and then run the F # project in F # interactive to run arbitrary form methods

EDIT : what are the steps for calling btShowNextNumber_Click in a running application?

 public partial class Form1 : Form { public Form1() { InitializeComponent(); } int i = 0; private void btShowNextNumber_Click(object sender, EventArgs e) { ++i; label1.Text = i.ToString(); } } 
+4
source share
5 answers

Sure. In F # interactive, you run something like:

 #r "MyDllName.dll" open MyNamespace // Call the constructor to get a new form, then show it let form = Form1() form.Show() // Call whatever public method you want form.MyMethodThatIWantToUse() 
+7
source

You can also add:

 Debugger.Launch() 

in the script. This will bring up a dialog asking which debugger to use. For instance. you can use the same instance of visual studio as the one you would use to execute the script.

+5
source
+2
source

F # is a CLR language such that C # or VB. This means that it can reference CLR assemblies (both DLLs and EXEs), import public classes from them, and call public methods and properties. If the class, method or property is not publicly available, you can still access them using reflection, but you have little to do.

Note that for WinForm interface elements to respond to user actions, you need to start the Windows message loop (using Application.Run ). In the case of the F # shell, it seems they run it in the background thread and send actions to this thread using Control.Invoke or its equivalents ( WindowsFormsSynchronizationContext ).

To call the method that you showed in the example, you need to do one of the following:

1) if the btShowNextNumber_Click method is public:

 form.Invoke(new Action(()=> form.btShowNextNumber_Click(form, EventArgs.Empty))); 

or

 SynchronizationContext.Current.Send(o => form.btShowNextNumber_Click(form, EventArgs.Empty)); 

2) if the btShowNextNumber_Click method btShowNextNumber_Click not public, but Button btShowNextNumber :

 form.Invoke(new Action(()=> form.btShowNextNumber.PerformClick()); 

or

 SynchronizationContext.Current.Send(o => form.btShowNextNumber.PerformClick()); 

As far as I understand how the F # shell works, you can configure the mail commands that you publish through SynchronizationContext.Send transparently, just like the IronPython shell does . I can’t say exactly how it works now. Need to check

+2
source

You need a debugger that supports managed code. It doesn’t matter which language is used to record the host of your code. I always debug code in different containers, such as MS Office, IE, Windows Explorer, Visual Studio and other VB / C # applications.

+1
source

All Articles