File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Pwsh/Modules/Text.Json/sketch Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -44,14 +44,16 @@ class SomePS {
44
44
[string ] $ProcessName
45
45
[int ] $Id
46
46
47
- # [example kind 2]: Serialize property if it's not null, but ignore it if it's null
48
- [JsonIgnoreAttribute ( Condition = [JsonIgnoreCondition ]::WhenWritingNull) ]
49
- [string ] $MainWindowTitle # next: test if ignore condition works on empty strings
50
47
51
48
# [example kind 1]: Property on instances to include, but, never serialize it
52
49
[Serialization.JsonIgnoreAttribute ()]
53
50
[Diagnostics.ProcessModuleCollection ] $Modules
54
51
52
+ # [example kind 2]: Serialize property if it's not null, but ignore it if it's null
53
+ # note: It does not work here beacuse [object][string]::empty is not null
54
+ [JsonIgnoreAttribute ( Condition = [JsonIgnoreCondition ]::WhenWritingNull) ]
55
+ [object ] $MainWindowTitle
56
+
55
57
SomePS ( [object ]$Other ) {
56
58
$WantedProps = [Linq.Enumerable ]::Intersect( # because linq is fun
57
59
[string []] $This.PSObject.Properties.Name ,
@@ -70,6 +72,7 @@ class SomePS {
70
72
$hasModules = get-process | ? Modules | select - First 1
71
73
$hasTitle = ( ps ) | ? MainWindowTitle | select - first 1
72
74
$noTitle = ( ps ) | ? -not MainWindowTitle | select - first 1
75
+ $notNullSite = (get-process | ? { $Null -eq $_.site })
73
76
74
77
# [a] works
75
78
$hasModules -as [SomePS []]
You can’t perform that action at this time.
0 commit comments