Skip to content

Remove type data for System.Array type #3222

Closed

Description

@PetSerAl

Type data for System.Array type contains single alias property Count -> Length. It was good for consistency, as ICollection.Count is implemented explicitly by arrays and was not visible while other collections types do not have Length property. But since PowerShell v3 it is possible to reference explicitly implemented interface members. So, this alias property no longer necessary. It also cause some headaches with ConvertTo-Json cmdlet:

PS> ConvertTo-Json (,1)
[
  1
]
PS> ConvertTo-Json ([PSObject](,1))
{
  "value": [
    1
  ],
  "Count": 1
}
PS> Remove-TypeData System.Array
PS> ConvertTo-Json (,1)
[
  1
]
PS> ConvertTo-Json ([PSObject](,1))
[
  1
]

Activity

  1. daxian-dbw commented on Feb 28, 2017

    @daxian-dbw
    Member

    It feels reasonable to remove the AliasProperty Count from System.Array, given that powershell now exposes the Count property implementation from ICollection interface. Feel free to submit a PR, the AliasProperty is defined here.

    As for ConvertTo-Json, the issue you listed seems to have been fixed in powershell core:

  2. added
    Issue-Enhancement
    on Feb 28, 2017
  3. iSazonov commented on Feb 28, 2017

    @iSazonov
    Collaborator

    Dongbo Wang (@daxian-dbw) What build do you use? I see the issue in alfa.16 (Windows 10 14936):

    PS C:\Program Files\PowerShell\6.0.0.16> ConvertTo-Json ([psobject](,1))
    {
        "value":  [
                      1
                  ],
        "Count":  1
    }
  4. PetSerAl commented on Feb 28, 2017

    @PetSerAl
    ContributorAuthor

    Dongbo Wang (@daxian-dbw) Is it OK to edit Types_Ps1Xml.generated.cs directly? I mean it have generated in name and this header:

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    

    It looks like it was automatically generated from Types.ps1xml file, but I can not find this file in repository.

  5. iSazonov commented on Feb 28, 2017

    @iSazonov
    Collaborator

    PetSerAl Now Types.ps1xml is in code for faster Powershell start. You can modify Types_Ps1Xml.generated.cs (see the file history on GitHub).

  6. lzybkr commented on Feb 28, 2017

    @lzybkr
    Contributor

    The file was generated to keep the ps1xml in sync, but we no longer maintain the ps1xml, so we should remove the comment and rename the file.

  7. daxian-dbw commented on Feb 28, 2017

    @daxian-dbw
    Member

    Ilya (@iSazonov) My bad, I must have tried that after Remove-TypeData. Removing the alias property Count will fix that.

  8. iSazonov commented on Feb 28, 2017

    @iSazonov
    Collaborator

    Dongbo Wang (@daxian-dbw) Clear.

    Jason Shirk (@lzybkr) I searched *generated.* - there are multiple files. Are there files that we also should fix?

  9. lzybkr commented on Feb 28, 2017

    @lzybkr
    Contributor

    For now, I would just change:

    GetEvent_Types_Ps1Xml.generated.cs
    TypesV3_Ps1Xml.generated.cs
    Types_Ps1Xml.generated.cs
    

    The files in GraphicalHost can be ignored, and the ones in the interpreter come from another project, so it would be better to not rename those.

  10. iSazonov commented on Feb 28, 2017

    @iSazonov
    Collaborator

    I opened Issue #3230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-Fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions