[API Proposal]: StrongBox.Create
#105400
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Runtime.CompilerServices
needs-further-triage
Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone
Background and motivation
Many generic types have static, non-generic, classes with a
Create
helper method. This allows the compiler to infer the generic argument.StrongBox<T>
does not.Arguably, since
StrongBox<T>
is inSystem.Runtime.CompilerServices
, it should not be used by user code. However, it is a useful type in multithreaded code as it allows atomic updates (by nature of being heap allocated), and avoids boxing/unboxing overhead; only an allocation. The unboxing overhead can be eliminated withUnsafe.Unbox
, but, as the name suggests, it's an unsafe API.API Proposal
API Usage
Old code:
New code:
Sure, target-typed
new
could be used on the old code, but some people disable that lint if the target type is not evident.Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: