Skip to content

Commit

Permalink
Pass non mapping to base serializer
Browse files Browse the repository at this point in the history
For PSObjects that are not dictionaries or PSCustomObjects, pass the
object directly to the base serializer.

Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Feb 20, 2025
1 parent c4a5e9b commit c2e85cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Binary file modified lib/net47/PowerShellYamlSerializer.dll
Binary file not shown.
Binary file modified lib/netstandard2.1/PowerShellYamlSerializer.dll
Binary file not shown.
12 changes: 12 additions & 0 deletions src/PowerShellYamlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,19 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
}

public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer) {
if (value is PSObject) {
var baseObj = ((PSObject)value).BaseObject;
if (!typeof(IDictionary).IsAssignableFrom(baseObj.GetType()) && !typeof(PSCustomObject).IsAssignableFrom(baseObj.GetType())) {
serializer(baseObj, baseObj.GetType());
return;
}
}

var psObj = (PSObject)value;
if (!typeof(IDictionary).IsAssignableFrom(psObj.BaseObject.GetType()) && !typeof(PSCustomObject).IsAssignableFrom(psObj.BaseObject.GetType())) {
serializer(psObj.BaseObject, psObj.BaseObject.GetType());
return;
}
var mappingStyle = this.useFlowStyle ? MappingStyle.Flow : MappingStyle.Block;
emitter.Emit(new MappingStart(AnchorName.Empty, TagName.Empty, true, mappingStyle));
foreach (var prop in psObj.Properties) {
Expand Down

0 comments on commit c2e85cf

Please sign in to comment.