Skip to content

Commit 8f39d2b

Browse files
feat: Import-TypeView -Namespace ( Fixes #224 )
1 parent cf8fa92 commit 8f39d2b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Commands/Types.PS1XML/Import-TypeView.ps1

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@
1818
$FilePath,
1919

2020
# If set, will generate an identical typeview for the deserialized form of each typename.
21+
[Parameter(ValueFromPipelineByPropertyName)]
2122
[switch]$Deserialized,
2223

24+
# The namespace to use for all imported types.
25+
# This will be prepended to the type name, and followed by a period.
26+
[Parameter(ValueFromPipelineByPropertyName)]
27+
[Alias('Prefix')]
28+
[string]$Namespace,
29+
2330
# Any file paths to exclude.
2431
[Parameter(ValueFromPipelineByPropertyName)]
2532
[SupportsWildcards()]
@@ -129,9 +136,10 @@
129136

130137
:nextMember foreach ($mt in $membersByType.GetEnumerator() | Sort-Object Key) { # Walk thru the members by type
131138
$WriteTypeViewSplat = @{ # and create a hashtable to splat.
132-
TypeName = $mt.Key
139+
TypeName = if ($Namespace) { "$Namespace.$($mt.Key)"} else {$mt.Key}
133140
Deserialized = $Deserialized
134141
}
142+
$OriginalParameterCount = $WriteTypeViewSplat.Count
135143
# Then, sort the values by name and by if it comes from this directory.
136144
$sortedValues = $mt.Value | Sort-Object Name, { $_.Directory.Name -ne $mt.Key }
137145

@@ -484,7 +492,8 @@ $stream.Dispose()
484492
$WriteTypeViewSplat.EventName = $eventNames
485493
}
486494

487-
if ($WriteTypeViewSplat.Count -gt 1) {
495+
# If we have added any parameters to splat, we will write the type view.
496+
if ($WriteTypeViewSplat.Count -gt $OriginalParameterCount) {
488497
$WriteTypeViewSplat.HideProperty = $hideProperty
489498
Write-TypeView @WriteTypeViewSplat
490499
}

0 commit comments

Comments
 (0)