Skip to content

Make PowerShell Classes Exportable Module Members #6293

@ephos

Description

@ephos

Steps to reproduce

Currently when classes are defined within a module it seems the best way to access them us with the following.

using module ModuleName
[Foo]::new()
Get-Module ModuleName

Expected behavior

Like other module members (functions, cmdlets, variables, aliases, etc) it would be helpful to be able to declare classes and export them as module members. Module manifests could have a section for this.

ClassesToExport = @()

Using them would feel more in line with how the rest of the language works. With the current implementation I find myself creating C# classes and importing the .cs file with Add-Type.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.15063.909
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.909
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions