dotnet / dotnet/fsharp

Generate C# extension members for type extensions

Open
#20,035 0 comments 0 reactions 0 assignees View on GitHub
Feature Request Needs-Triage
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

Hi,

A library written in F# does not expose type extensions done in other modules - see discussion here https://github.com/dotnet/fsharp/discussions/20032 and my example code here https://github.com/ernestasjuska/FSharpIssues.TypeExtensionsDemo/blob/main/TypeExtensionsDemo/Program.cs.

Some of the problem is that type extensions generate method names like `Thing.get_Texture` that are not visible from C# code.
For now, the workaround is to write missing extension members on C# side by hand (or source generate).

https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/type-extensions only describes the old extension methods way using `[]` attribute.

So, I wish there was something like `[]` attribute that could be applied to F# type extension so type extension would be available in C# code.

This is low priority and not critical.

Thanks.

P.S. I already tried to see if it is possible to at least write extension members code manually. From C# end it needs reflection so that is not nice (but it is very easy) and from F# I hit the limitation that types cannot be nested so I could not mimic the extension members markers that are generated inside assembly DLL.

Contributor guide

Open the contributing guide

Research direction

Start with the linked discussion and the TypeExtensionsDemo/Program.cs example to understand the C# visibility problem, then compare it with the linked F# type-extensions documentation. Define the desired ExtensionMembers behavior and verify that F# type extension members can be consumed from C# without hand-written wrappers.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, fsharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.