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 86bb4d6
Show file tree
Hide file tree
Showing 3 changed files with 4 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.
4 changes: 4 additions & 0 deletions src/PowerShellYamlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria

public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer) {
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 86bb4d6

Please sign in to comment.