[API Proposal]: An attribute to indicate boxed value type is not expected for certain API #91191
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Diagnostics
Milestone
Background and motivation
There are APIs that accepts
object
and operates with object identity, thus boxed structs will not work.Examples including:
GC.KeepAlive (For keeping the collectible type alive, willKeepAlive(value.GetType())
be better?)ArgumentNullException.ThrowIfNull (#85154) is similar, but the motivation is different, and will have different meaning with nullable value type.
With such an attribute, we can have one analyzer for all these APIs, without recognizing them one by one, and also works for user code. Can it be reviewed together?
API Proposal
The analyzer will warn if the declared type of the parameter is value type.
API Usage
Alternative Designs
Should it be named as what's expected, or what's unexpected?
Should it be inherited?
Should we include a custom diagnostic id for analyzer? Users are unlikely to suppress such warnings though.
Risks
No response
The text was updated successfully, but these errors were encountered: