PolySharp icon indicating copy to clipboard operation
PolySharp copied to clipboard

Deconstruct extension for KeyValuePair<TKey, TValue>

Open Arthri opened this issue 2 years ago • 1 comments

Description (optional)

Add an extension to KeyValuePair<TKey, TValue> that mirrors https://learn.microsoft.com/en-US/dotnet/api/system.collections.generic.keyvaluepair-2.deconstruct?view=net-7.0

Rationale

The extension allows for KeyValuePairs to be deconstructed in scenarios such as

foreach ((var k, var v) in dict)
{
    // ...
}

Proposed API

https://learn.microsoft.com/en-US/dotnet/api/system.collections.generic.keyvaluepair-2.deconstruct?view=net-7.0 Allows the compiler to deconstruct KeyValuePairs in tuple patterns or other tuple-like scenarios

Drawbacks

Not known

Alternatives

Not known

Other thoughts

None

Arthri avatar Dec 18 '22 03:12 Arthri

I think this is a duplicate with #6 , same things discussed (also support for Deconstruct extensions methods)

maximpashuk avatar Jan 13 '23 03:01 maximpashuk