Skip to content

Commit a06fa38

Browse files
feat: Write-TypeView -DefaultKey ( Fixes #221 )
1 parent 716d720 commit a06fa38

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

Commands/Types.PS1XML/Write-TypeView.ps1

+28-5
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@
100100
[string[]]$EventName,
101101

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

106+
# The default key property set.
107+
# This is the set of properties that will be used as the key for the object.
108+
[string[]]$DefaultKey,
109+
107110
# The ID property
108111
[string]$IdProperty,
109112

@@ -250,6 +253,7 @@ if (`$Eventhandler -is [Management.Automation.PSEventSubscriber]) {
250253
if ($psBoundParameters.ContainsKey('SerializationDepth') -or
251254
$psBoundParameters.ContainsKey('IdProperty') -or
252255
$psBoundParameters.ContainsKey('DefaultDisplay') -or
256+
$psBoundParameters.ContainsKey('DefaultKey') -or
253257
$psBoundParameters.ContainsKey('Reserializer')) {
254258
$defaultDisplayXml = if ($psBoundParameters.ContainsKey('DefaultDisplay')) {
255259
if ($DebugBuild) {
@@ -263,6 +267,20 @@ if (`$Eventhandler -is [Management.Automation.PSEventSubscriber]) {
263267
$referencedProperties
264268
</ReferencedProperties>
265269
</PropertySet>
270+
"
271+
}
272+
$defaultKeyXml = if ($psBoundParameters.ContainsKey('DefaultKey')) {
273+
if ($DebugBuild) {
274+
Update-TypeData @updateSplat -DefaultKeyPropertySet $DefaultKey
275+
}
276+
$referencedProperties = "<Name>" + ($DefaultKey -join "</Name>
277+
<Name>") + "</Name>"
278+
" <PropertySet>
279+
<Name>DefaultKeyPropertySet</Name>
280+
<ReferencedProperties>
281+
$referencedProperties
282+
</ReferencedProperties>
283+
</PropertySet>
266284
"
267285
}
268286
$serializationDepthXml = if ($psBoundParameters.ContainsKey('SerializationDepth')) {
@@ -293,9 +311,14 @@ if (`$Eventhandler -is [Management.Automation.PSEventSubscriber]) {
293311
<MemberSet>
294312
<Name>PSStandardMembers</Name>
295313
<Members>
296-
$defaultDisplayXml
297-
$serializationDepthXml
298-
$reserializerXml
314+
$(
315+
@(
316+
$defaultDisplayXml
317+
$DefaultKeyXml
318+
$serializationDepthXml
319+
$reserializerXml
320+
) -ne $null -join [Environment]::NewLine
321+
)
299322
</Members>
300323
</MemberSet>
301324
"

0 commit comments

Comments
 (0)