From 8f39d2b52fafd43e5852d758f7ffa512a3b7f573 Mon Sep 17 00:00:00 2001 From: StartAutomating Date: Sun, 7 Jul 2024 12:33:07 -0700 Subject: [PATCH] feat: Import-TypeView -Namespace ( Fixes #224 ) --- Commands/Types.PS1XML/Import-TypeView.ps1 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Commands/Types.PS1XML/Import-TypeView.ps1 b/Commands/Types.PS1XML/Import-TypeView.ps1 index db62590..3ba7ed9 100644 --- a/Commands/Types.PS1XML/Import-TypeView.ps1 +++ b/Commands/Types.PS1XML/Import-TypeView.ps1 @@ -18,8 +18,15 @@ $FilePath, # If set, will generate an identical typeview for the deserialized form of each typename. + [Parameter(ValueFromPipelineByPropertyName)] [switch]$Deserialized, + # The namespace to use for all imported types. + # This will be prepended to the type name, and followed by a period. + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('Prefix')] + [string]$Namespace, + # Any file paths to exclude. [Parameter(ValueFromPipelineByPropertyName)] [SupportsWildcards()] @@ -129,9 +136,10 @@ :nextMember foreach ($mt in $membersByType.GetEnumerator() | Sort-Object Key) { # Walk thru the members by type $WriteTypeViewSplat = @{ # and create a hashtable to splat. - TypeName = $mt.Key + TypeName = if ($Namespace) { "$Namespace.$($mt.Key)"} else {$mt.Key} Deserialized = $Deserialized } + $OriginalParameterCount = $WriteTypeViewSplat.Count # Then, sort the values by name and by if it comes from this directory. $sortedValues = $mt.Value | Sort-Object Name, { $_.Directory.Name -ne $mt.Key } @@ -484,7 +492,8 @@ $stream.Dispose() $WriteTypeViewSplat.EventName = $eventNames } - if ($WriteTypeViewSplat.Count -gt 1) { + # If we have added any parameters to splat, we will write the type view. + if ($WriteTypeViewSplat.Count -gt $OriginalParameterCount) { $WriteTypeViewSplat.HideProperty = $hideProperty Write-TypeView @WriteTypeViewSplat }