F# – Make extension methods visible to C#

In F# you can write an exten­sion method like this:


Whilst this will work per­fect­ly fine in your F# code, the exten­sion method will not be vis­i­ble to any C# code using the File­In­fo type because F# and C# com­piles exten­sion meth­ods dif­fer­ent­ly.

To make C#-compatible exten­sion meth­ods in F#, here’s what you need to do instead:


That’s it, just fol­low these 3 sim­ple steps and you’re done:

  1. wrap the exten­sion meth­ods inside a class dec­o­rat­ed with the [<Exten­sion>] attribute
  2. write the exten­sion meth­ods as sta­t­ic mem­bers where the first argu­ment is of the type which should be extend­ed (like how you would write an exten­sion method in C#)
  3. mark the exten­sion meth­ods with the [<Exten­sion>] attribute

Liked this post? Why not support me on Patreon and help me get rid of the ads!