Skip to content

Commit

Permalink
feat: Write-TypeView -DefaultKey ( Fixes #221 )
Browse files Browse the repository at this point in the history
  • Loading branch information
StartAutomating committed Jul 7, 2024
1 parent 716d720 commit a06fa38
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions Commands/Types.PS1XML/Write-TypeView.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@
[string[]]$EventName,

# The default display.
# If only one propertry is used, this will set the default display property.
# If more than one property is used, this will set the default display member set.
# This is the default set of properties to display if no formatter is specified.
[string[]]$DefaultDisplay,

# The default key property set.
# This is the set of properties that will be used as the key for the object.
[string[]]$DefaultKey,

# The ID property
[string]$IdProperty,

Expand Down Expand Up @@ -250,6 +253,7 @@ if (`$Eventhandler -is [Management.Automation.PSEventSubscriber]) {
if ($psBoundParameters.ContainsKey('SerializationDepth') -or
$psBoundParameters.ContainsKey('IdProperty') -or
$psBoundParameters.ContainsKey('DefaultDisplay') -or
$psBoundParameters.ContainsKey('DefaultKey') -or
$psBoundParameters.ContainsKey('Reserializer')) {
$defaultDisplayXml = if ($psBoundParameters.ContainsKey('DefaultDisplay')) {
if ($DebugBuild) {
Expand All @@ -263,6 +267,20 @@ if (`$Eventhandler -is [Management.Automation.PSEventSubscriber]) {
$referencedProperties
</ReferencedProperties>
</PropertySet>
"
}
$defaultKeyXml = if ($psBoundParameters.ContainsKey('DefaultKey')) {
if ($DebugBuild) {
Update-TypeData @updateSplat -DefaultKeyPropertySet $DefaultKey
}
$referencedProperties = "<Name>" + ($DefaultKey -join "</Name>
<Name>") + "</Name>"
" <PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
$referencedProperties
</ReferencedProperties>
</PropertySet>
"
}
$serializationDepthXml = if ($psBoundParameters.ContainsKey('SerializationDepth')) {
Expand Down Expand Up @@ -293,9 +311,14 @@ if (`$Eventhandler -is [Management.Automation.PSEventSubscriber]) {
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
$defaultDisplayXml
$serializationDepthXml
$reserializerXml
$(
@(
$defaultDisplayXml
$DefaultKeyXml
$serializationDepthXml
$reserializerXml
) -ne $null -join [Environment]::NewLine
)
</Members>
</MemberSet>
"
Expand Down

0 comments on commit a06fa38

Please sign in to comment.