In F# you can write an extension method like this:

Whilst this will work perfectly fine in your F# code, the extension method will not be visible to any C# code using the FileInfo type because F# and C# compiles extension methods differently.
To make C#-compatible extension methods in F#, here’s what you need to do instead:

That’s it, just follow these 3 simple steps and you’re done:
- wrap the extension methods inside a class decorated with the [<Extension>] attribute
- write the extension methods as static members where the first argument is of the type which should be extended (like how you would write an extension method in C#)
- mark the extension methods with the [<Extension>] attribute




Is it possible to write just one definition that will work in both C# and F#?
Dmitri — the C# compatible version works in both F# and C#. In general, you can use extension methods defined in C# from F#.