[Proposal]: Nullable value types in attribute usage #4203
Replies: 4 comments 10 replies
-
Part of the problem here is that nullable value types cannot be emitted as a |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I don't understand, why do you have to define the attribute with a backing field? Can't you make it a public class FooAttribute : Attribute
{
public bool Boolean { get; set; }
} Even like this, you should still be able to differentiate between |
Beta Was this translation helpful? Give feedback.
-
Another alternative would be to provide a secondary constructor: public class FooAttribute : Attribute
{
public bool? Boolean { get; }
public FooAttribute() { }
public FooAttribute(bool flag) => Boolean = flag;
} Though, I admit, this is only feasible when you only have 1 (or maaaaaybe 2) of these properties. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Nullable value types in attribute usage
Summary
Remove the restrictions of setting nullable value types in attribute usages.
Motivation
Currently, the following code yields a
CS0655
:This is often an annoyance because I have to fully implement the property with a "backing field":
Detailed design
N/A
Drawbacks
The status quo is a drawback.
Alternatives
N/A
Unresolved questions
Design meetings
Beta Was this translation helpful? Give feedback.
All reactions