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
Fix for deserializing imported ordered dictionary #15545
Fix for deserializing imported ordered dictionary #15545
Conversation
…s ordered dictionary
test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1
Outdated
Show resolved
Hide resolved
4bcdf6f
to
d936a79
Compare
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@PaulHigin can you please take a look at this PR and see the change to |
These changes look right to me, except that instead of having if/else blocks, I feel it would be cleaner if you created a helper class that encapsulates the dictionary types (Hashtable or OrderedDictionary) and handles adding key/value pairs and re-creating with case sensitive comparer as needed. Something like:
private class PSDictionary
{
private Hashtable table;
private OrderedDictionary orderedDictionary;
public PSDictionary(bool isOrdered) { ... }
public Add(object key, object value) { ... }
public object DictionaryObject { get { return _isOrdered ? orderedDictionary : table; } }
}Also, I think it is fine to compare the type name check to a hard coded constant string: System.Collections.Specialized.OrderedDictionary, instead of getting the full type name from an instance of the object.
Done
Did not make the this change, as it seems to me that it safer not to assume the type name. Note that with the other changes |
48eae01
to
b061f92
Compare
Added test cases for the keys clash. I didn't add them initially as they are not directly related to this PR change. Most of the added tests I created use a manual "exported" XML, as I did not find a way to create hashtable (ordered or not) that includes duplicate keys, or an ordered hashtable that allows case-sensitive keys. The only added test without using XML is for non-ordered case-sensitive hashtable using In the added tests I didn't find a way to check which "Comparer" is set for the imported table. Therefore the tests only check the number of elements in the imported table. Also note that I rewrote the change using the |
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? |
|
@davidBar-On Thanks for your contribution! |
|
Handy links: |


PR Summary
Suggested fix for issue #2861 - exported ordered dictionary is now imported via
Import-ClixmlasOrderedDictionaryand not asHashtable. This is done by checking if the imported dictionary type names include type ofOrderedDictionary.PR Context
Fix #2861.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).