Skip to content

Commit c2e85cf

Browse files
Pass non mapping to base serializer
For PSObjects that are not dictionaries or PSCustomObjects, pass the object directly to the base serializer. Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent c4a5e9b commit c2e85cf

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

src/PowerShellYamlSerializer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,19 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
123123
}
124124

125125
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer) {
126+
if (value is PSObject) {
127+
var baseObj = ((PSObject)value).BaseObject;
128+
if (!typeof(IDictionary).IsAssignableFrom(baseObj.GetType()) && !typeof(PSCustomObject).IsAssignableFrom(baseObj.GetType())) {
129+
serializer(baseObj, baseObj.GetType());
130+
return;
131+
}
132+
}
133+
126134
var psObj = (PSObject)value;
135+
if (!typeof(IDictionary).IsAssignableFrom(psObj.BaseObject.GetType()) && !typeof(PSCustomObject).IsAssignableFrom(psObj.BaseObject.GetType())) {
136+
serializer(psObj.BaseObject, psObj.BaseObject.GetType());
137+
return;
138+
}
127139
var mappingStyle = this.useFlowStyle ? MappingStyle.Flow : MappingStyle.Block;
128140
emitter.Emit(new MappingStart(AnchorName.Empty, TagName.Empty, true, mappingStyle));
129141
foreach (var prop in psObj.Properties) {

0 commit comments

Comments
 (0)