Access protected const from base class in attribute
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
Environment: I am using .Net Framework 4.6.1 together with the target F# runtime 4.1 (FSharp.Core, 4.4.1.0) in a F# class library which references XUnit (2.2.0, obtained via NuGet) in Visual Studio 2017 Community.
I have a C# base class with a constant
```cs
public class TestClassBase
{
protected const string Foo = "Bar";
}
```
which I can consume in C# as follows
```cs
[Trait(Foo, "")]
public class MyCSharpTestClass : TestClassBase
{
}
```
How do I consume it in a F# class? `Foo` is not recognized by the compiler.
```fs
[]
type MyFSharpTestClass() =
inherit TestClassBase()
```
The error I get is: FS0267 This is not a valid constant expression or custom attribute value.
`[]` yields: FS0039 The value or constructor 'Foo' is not defined. Maybe you want one of the following: floor.
`[]` yields FS0039 The value, namespace, type or module 'this' is not defined. Maybe you want one of the following: ThisAssembly.
`[]` yields FS0039 The value, namespace, type or module 'base' is not defined. Maybe you want one of the following: Base.
`[]` yields FS0039 The field, constructor or member 'Foo' is not defined.
Contributor guide
Assessment
This issue has not been assessed yet.