dotnet / dotnet/fsharp

Ensure that customattributes on target functions are accessible via FSharpFunc<_,_>

Open
#17,858 4 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-CodeGen Feature Request
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

**Is your feature request related to a problem? Please describe.**

Hello, hope you're good. I'm taking a look at the available approaches for reading custom attributes from a function definition and eventually found this page from StackOverflow: https://stackoverflow.com/a/65157463/10146684.

The way of doing this, according to this answer from SO, demands the knowledge of the module that the function is defined, which does not really fit my needs.

Then, I thought that it could be more practical if the attributes defined for a specific function were "[bubbled-up](https://stackoverflow.com/a/1355656/10146684)" to the `FSharpFunc<_,_>` instance, so we can directly retrieve those attributes from it.

Disclaimer: I don't know the real impact of this change, but at least in theory I think it makes sense.

**Describe the solution you'd like**

Replicate the function attributes at the `FSharpFunc<_,_>` instance to make it easier to retrieve this information for functions, using something like:

```fsharp
type MyAttribute(value: int) =
inherit System.Attribute()
member this.Value = value

[]
let myFunction() = ()

myFunction.GetType().GetCustomAttributes(true)
```

**Describe alternatives you've considered**

-

**Additional context**

-

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.