8000 ConvertTo-Csv / Export-Csv - Serialize IDictionary objects with key/value pairs as properties by vexx32 · Pull Request #11029 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

ConvertTo-Csv / Export-Csv - Serialize IDictionary objects with key/value pairs as properties #11029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2021

Conversation

vexx32
Copy link
Collaborator
@vexx32 vexx32 commented Nov 10, 2019

PR Summary

Updates ConvertTo-Csv and Export-Csv to handle IDictionary objects.

With this change, the behaviour for IDictionary inputs are changed in ConvertTo-Csv and Export-Csv:

  1. If the InputObject is not IDictionary, behaviour remains as per existing behaviour.
  2. If the InputObject is IDictionary:
  • When pulling property names, we only check the dictionary's Keys and any additional instance properties (e.g., those added with Add-Member or Select-Object)
  • When looking for values, we first check the dictionary to see if the key is present. If it is, use the corresponding value. If it is not, we also check any instance properties with the same name and use those values if available.

The reason we also check for any instance properties is based on the assumption that if a user is adding extra properties to their IDictionary objects, they likely want to keep them as intact as possible.

We do however ignore standard properties completely, since with IDictionary objects these are typically of little value when serialized to string.

Note that since both Export-Csv and ConvertTo-Csv utilise the same helper methods, tests were only added to the ConvertTo-Csv test file in order to minimise the duplication of code.

Example

Example of ConvertTo-Csv with hashtables as input, then again with instance properties attached to the hashtable.

PR Context

Resolves #10999

PR Checklist

@vexx32 vexx32 requested a review from SteveL-MSFT November 10, 2019 04:33
@vexx32 vexx32 added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 10, 2019
@vexx32 vexx32 requested review from SteveL-MSFT and iSazonov and removed request for SteveL-MSFT November 13, 2019 17:18
@iSazonov iSazonov self-assigned this Nov 14, 2019
@vexx32
Copy link
Collaborator Author
vexx32 commented Nov 15, 2019

Added a doc issue for these changes. 😊

@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Nov 15, 2019
@vexx32
Copy link
Collaborator Author
vexx32 commented Nov 18, 2019

@SteveL-MSFT please update your review when you have a moment 💖 😊

@mi-hol
Copy link
mi-hol commented Mar 21, 2020

@vexx32 is there any chance to complete this for the 7.1 preview?

@vexx32
Copy link
Collaborator Author
vexx32 commented Mar 21, 2020

@mi-hol the code here is as functional as it gets. ^^

I'll rebase the commits to take care of the merge conflict and ensure that everything works as expected, but whether it makes the 7.1-preview release is entirely up the other folks here, I'm afraid. 🙂

/cc @SteveL-MSFT

8000
@vexx32 vexx32 force-pushed the CsvDictionaryHandling branch from 59919fd to f130cd2 Compare March 21, 2020 22:44
@vexx32
Copy link
Collaborator Author
vexx32 commented Apr 24, 2020

@SteveL-MSFT could you please update your review? Thanks! 😊

@vexx32 vexx32 requested a review from SteveL-MSFT April 24, 2020 19:00
@iSazonov iSazonov added this to the 7.1.0-preview.3 milestone Apr 25, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label May 27, 2020
@ghost
Copy link
ghost commented May 27, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@iSazonov
Copy link
Collaborator

@SteveL-MSFT Could you please review or delegate this anybody?

@ghost ghost removed the Review - Needed The PR is being reviewed label Jun 11, 2020
@mi-hol
Copy link
mi-hol commented Jun 17, 2020

@TravisEz13 last change 'remove label' applied by bot seems incorrect.
Maybe this one of the reasons this PR is not progressing?

@vexx32
Copy link
Collaborator Author
vexx32 commented Jun 24, 2020

@SteveL-MSFT friendly ping for review. 😊

@adityapatwardhan adityapatwardhan removed this from the 7.1.0-preview.4 milestone Jun 29, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label Jul 7, 2020
@ghost
Copy link
ghost commented Jul 7, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@iSazonov
Copy link
Collaborator

@vexx32 Please rebase to update CIs.

@ghost ghost removed the Review - Needed The PR is being reviewed label Dec 10, 2020
- Add tests for ConvertTo-Csv

Update src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs

Co-Authored-By: Ilya <darpa@yandex.ru>

Update test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1
@vexx32 vexx32 force-pushed the CsvDictionaryHandling branch from f130cd2 to 2397ca0 Compare December 10, 2020 21:45
@ghost ghost added the Review - Needed The PR is being reviewed label Dec 18, 2020
@ghost
Copy link
ghost commented Dec 18, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@SteveL-MSFT SteveL-MSFT reopened this Jul 21, 2021
@ghost ghost removed the Review - Needed The PR is being reviewed label Jul 21, 2021
@SteveL-MSFT
Copy link
Member

@iSazonov I think this one is ready

@iSazonov
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link
Azure Pipelines successfully started running 5 pipeline(s).

@iSazonov iSazonov enabled auto-merge (squash) July 22, 2021 02:47
@iSazonov iSazonov merged commit efa9b25 into PowerShell:master Jul 22, 2021
@iSazonov iSazonov added this to the 7.2.0-preview.8 milestone Jul 22, 2021
@vexx32 vexx32 deleted the CsvDictionaryHandling branch July 22, 2021 13:16
@ghost
Copy link
ghost commented Aug 23, 2021

🎉v7.2.0-preview.9 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link
ghost commented Sep 28, 2021

🎉v7.2.0-preview.10 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Export-Csv and ConvertTo-Csv support hashtables (dictionaries)
6 participants
0