Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Supporting C# 7 deconstruction of certain types #14621

Closed
wants to merge 3 commits into from
Closed

Supporting C# 7 deconstruction of certain types #14621

wants to merge 3 commits into from

Conversation

AlexRadch
Copy link

C# 7 added support for deconstruction of user-defined types via a Deconstruct(out ...) method. It would make sense to be able to use this feature with tuple-like types such as KeyValuePair and DictionaryEntry.
Close https://github.com/dotnet/corefx/issues/13746

IDictionary<TKey, TValue> dictionary = GenericIDictionaryFactory(count);

Assert.All(dictionary, KeyValuePair_Deconstruct);
Assert.True(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am debugging that xUnit call this test. I will remove this after I see that it fail here. It is just for me.

{
IDictionary<TKey, TValue> dictionary = GenericIDictionaryFactory(count);

Assert.All(dictionary, KeyValuePair_Deconstruct);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be cleaner if it was just one method. Splitting KeyValuePair_Deconstruct to a helper method is unnecessary unless we're overriding it somewhere.

Copy link
Author

@AlexRadch AlexRadch Dec 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be used to test deconstruction in other methods. For example I can create test for empty pair deconstruction and use this method in new test. I did not create such testing because it seems useless, but it is good to split one method to logical parts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is good to split one method to logical parts.

Generally yeah, but the calling method is only two lines. We have to be careful with the helper method style because it moves the test logic out of the test itself and makes the code overall more difficult to follow. So unless we have a good reason for it (e.g. other tests that use the same logic like KeyValuePair_ToString), we should keep the code consolidated.

foreach (DictionaryEntry entry in dictionary)
{
DictionaryEntry_Deconstruct(entry);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Assert.All.

Also, same comment on above about helper method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.All was before here. But it is only for generic and can not be compiled here.

@karelz
Copy link
Member

karelz commented Jan 11, 2017

@AlexRadch do you plan to finish the work?

@karelz
Copy link
Member

karelz commented Jan 19, 2017

The PR seems to be abandoned. Closing for now.

@karelz karelz closed this Jan 19, 2017
@karelz karelz modified the milestone: 2.0.0 Jan 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants