C#/F# interoperability
There are helper classes included in WebSharper for most common conversions between FSharp.Core and standard .NET types.
These conversions work both on server and client side.
Create F# values from standard .NET counterparts
The WebSharper.FSharpConvert static class contains static members to create values used commonly in F#.
- FSharpConvert.Funoverloads create curried F# functions for 1-8 arguments from- System.Actionand- System.Funcdelegate values.
- FSharpConvert.Optionoverloads create an- FSharpOption<T>value from a value of a .NET reference type or- Nullablevalue type. (To create a 1)
- FSharpConvert.Listoverloads create an- FSharpList.
- FSharpConvert.Asyncoverloads create an- FSharpAsync<TResult>from a- Taskor- Task<TResult>.
- FSharpConvert.Refoverloads create an- FSharpRefobject with specified initial value or default value for a type.
- Option.Noneand F#- unitvalues can be just- null.
Consume F# values from C#
Everything works as in .NET, there are no extra helpers provided by WebSharper.
- To call an FSharpFuncfunction, use itsInvokemethod. When calling curried F# functions, you have to chain callingInvoketo pass all arguments separately.
- Create F# union values using the .New...static method in the union type (or property for a union case with no fields).
- Create F# record values by using its constructor.
- Separate union cases by using the Is...methods, or theTagproperty. Whenever a union hasnullas possible value, these methods are static.
- For the FSharpOptiontype, you can usex?.Value) to get the value or null.