Summary of the new feature/enhancement
Using modern types such as List/OrderedList/SortedList/etc. is becoming more common for performance reasons, but the array manipulation operators reconstruct these as [Object[]] which is not ideal for many already discussed reasons, and using other syntax such as .Add() is awkward especially for newer Powershell Users. Dictionary does not have this issue as the property assignment operators work fine.
I propose that, if a class implements IList and does not have op_Addition or op_Subtraction already defined, that the operators will use the standard IList Add and Remove methods to manipulate the array and preserve it rather than recasting all the contents into a new [Object[]].
This will allow users who want to use more advanced types for performance to be able to do so without breaking any behavior of @() syntax or normal powershell user experience.
NOTE: #5643 proposed a lot of syntactic sugar around lists or replacing the default type with lists. This Feature Request is smaller in scope but compatible and is less likely to cause breaking regressions.
Potential Breaking Changes
- Scripts that anticipate the existing behavior of casting to an
[Object[]] and work around it could break, but it would have to be very specific and very rare edge case, for instance something that recasts it to a list would simply just cast a list to a list and not break. Could be controlled with a preference variable
EDITS
- Narrowed scope to just
+= and -= operators due to @SeeminglyScience's valid concerns
Summary of the new feature/enhancement
Using modern types such as List/OrderedList/SortedList/etc. is becoming more common for performance reasons, but the array manipulation operators reconstruct these as
[Object[]]which is not ideal for many already discussed reasons, and using other syntax such as.Add()is awkward especially for newer Powershell Users.Dictionarydoes not have this issue as the property assignment operators work fine.I propose that, if a class implements
IListand does not haveop_Additionorop_Subtractionalready defined, that the operators will use the standardIListAddandRemovemethods to manipulate the array and preserve it rather than recasting all the contents into a new[Object[]].This will allow users who want to use more advanced types for performance to be able to do so without breaking any behavior of
@()syntax or normal powershell user experience.NOTE: #5643 proposed a lot of syntactic sugar around lists or replacing the default type with lists. This Feature Request is smaller in scope but compatible and is less likely to cause breaking regressions.
Potential Breaking Changes
[Object[]]and work around it could break, but it would have to be very specific and very rare edge case, for instance something that recasts it to a list would simply just cast a list to a list and not break. Could be controlled with a preference variableEDITS
+=and-=operators due to @SeeminglyScience's valid concerns