-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.The question is answered.WG-Languageparser, language semanticsparser, language semantics
Description
I'm looking for a supported way to reduce the namespace repetition I mentioned in #5940.
about_Using includes the following statement:
The
usingstatement needs to be the first statement in the script.
Modules customarily dot-source individual .ps1 files from their .psm1. Pester is one such example. It's not clear to me how the above statement applies in the context of such a module.
Consider the following files:
UsingTest.psm1
@(
'fileA.ps1'
'fileB.ps1'
) |
% { . "$(Split-Path -Path $MyInvocation.MyCommand.Path)\$_" }
function Get1 { [int][MyEnum]::One }fileA.ps1
using namespace UsingTest.A
Add-Type @'
namespace UsingTest { namespace A {
public enum MyEnum {
One = 1,
Two
}
}
}
'@
function GetA1 { return [int][MyEnum]::One }
$script:v1 = 1fileB.ps1
using namespace UsingTest.B
Add-Type @'
namespace UsingTest { namespace B {
public enum MyEnum {
One = 101,
Two
}
}
}
'@
function GetB1 { [int][MyEnum]::One }
function GetV1 { $script:v1 }- Is this a supported use of
using? - Is it certain that
GetA1andGetB1will return1and101, respectively? - How does the statement that "the
usingstatement needs to be the first statement in the script" apply to such a module? - Is there some other way large modules should be structured?
Edit: Add $script:v1 statements.
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.The question is answered.WG-Languageparser, language semanticsparser, language semantics