4
4
. Synopsis
5
5
Imports a Type View
6
6
. Description
7
- Imports a Type View, defined in a external file .method or .property file
7
+ Imports a Type View, defined in a external file.
8
8
. Link
9
9
Write-TypeView
10
10
. Example
111
111
112
112
# Congratulations! These very few lines are all it takes to enable inheritance!
113
113
}
114
- }
114
+ }
115
115
}
116
116
}
117
117
}
@@ -333,7 +333,12 @@ data { $([ScriptBlock]::Create($fileText)) }
333
333
$aliasProperty = (& $dataScriptBlock ) -as [Collections.IDictionary ]
334
334
} elseif (-not $noteProperty.Contains ($itemName )) {
335
335
# otherwise, we load it in a ScriptProperty
336
- $scriptPropertyGet [$itemName ] = $dataScriptBlock
336
+ $scriptPropertyGet [$itemName ] = @"
337
+ `$ dataObjects = $dataScriptBlock
338
+ # Overwrite our own static property with an instance property.
339
+ `$ this.psobject.properties.add([PSNoteProperty]::new('$itemName ', `$ dataObjects), `$ true)
340
+ return `$ dataObjects
341
+ "@
337
342
}
338
343
}
339
344
# endregion .psd1 Files
@@ -342,9 +347,12 @@ data { $([ScriptBlock]::Create($fileText)) }
342
347
# Xml content is cached inline in a ScriptProperty and returned casted to [xml]
343
348
if (-not $noteProperty.Contains ($itemName )) {
344
349
$scriptPropertyGet [$itemName ] = [ScriptBlock ]::Create(@"
345
- [xml]@'
350
+ `$ fileTextAsXml = [xml]@'
346
351
$fileText
347
352
'@
353
+ # Overwrite our own static property with an instance property.
354
+ `$ this.psobject.properties.add([PSNoteProperty]::new('$itemName ', `$ fileTextAsXml), `$ true)
355
+ return `$ fileTextAsXml
348
356
"@ )
349
357
}
350
358
}
@@ -354,9 +362,12 @@ $fileText
354
362
# Json files are piped to ConvertFrom-Json
355
363
if (-not $noteProperty.Contains ($itemName )) {
356
364
$scriptPropertyGet [$itemName ] = [ScriptBlock ]::Create(@"
357
- @'
365
+ `$ convertedFromJson = @'
358
366
$fileText
359
367
'@ | ConvertFrom-Json
368
+ # Overwrite our own static property with an instance property.
369
+ `$ this.psobject.properties.add([PSNoteProperty]::new('$itemName ', `$ convertedFromJson), `$ true)
370
+ return `$ convertedFromJson
360
371
"@ )
361
372
}
362
373
}
@@ -366,9 +377,12 @@ $fileText
366
377
.clixml {
367
378
if (-not $noteProperty.Contains ($itemName )) {
368
379
$scriptPropertyGet [$itemName ] = [ScriptBlock ]::Create(@"
369
- [Management.Automation.PSSerializer]::Deserialize(@'
380
+ `$ deserialized = [Management.Automation.PSSerializer]::Deserialize(@'
370
381
$fileText
371
382
'@)
383
+ # Overwrite our own static property with an instance property.
384
+ `$ this.psobject.properties.add([PSNoteProperty]::new('$itemName ', `$ deserialized), `$ true)
385
+ return `$ deserialized
372
386
"@ )
373
387
}
374
388
}
@@ -472,7 +486,7 @@ $stream.Dispose()
472
486
}
473
487
474
488
if ($WriteTypeViewSplat.Count -gt 1 ) {
475
- $WriteTypeViewSplat.HideProperty = $hideProperty
489
+ $WriteTypeViewSplat.HideProperty = $hideProperty
476
490
Write-TypeView @WriteTypeViewSplat
477
491
}
478
492
}
0 commit comments