You can expose any valid F# function name to C# as any C# valid function name using CompiledName attribute:
namespace Library1
module Test =
[<CompiledName("Whatever")>]
let ``add a and b`` x y = x + y
and then in C#:
using Library1;
...............
System.Console.WriteLine(Test.Whatever(2,2));
FOLLOW-UP 03/05/2016 on comment from NickL, applies at least to F#3.1:
Moving from functions to members brings some "ifs and buts".
To begin with, CompiledName
attribute does not compile with member
if being used from pure namespace
. The mere compilation requires use within a module
.
When being used within a module
and decorating method member
of F# record it works just fine regardless of how the contents between two ticks looks. However when decorating property member
of F# record CompiledName
is visible cross-assembly only if contents between double ticks resembles some legal value name:
module M
type MyRecord =
{ myField: string }
[<CompiledName "Whatever">]
member x.``Blah Blah blah``() = x.myField
[<CompiledName "Another">]
member x.``ABC`` = x.myField
and then from C# the following works OK:
var recInC = new M.MyRecord("Testing...");
Console.WriteLine(recInC.Whatever());
Console.WriteLine(recInC.Another);
Such inconsistencies prompt for potential issues.