diff --git a/lib/net47/PowerShellYamlSerializer.dll b/lib/net47/PowerShellYamlSerializer.dll index ad5b86b..4693a50 100644 Binary files a/lib/net47/PowerShellYamlSerializer.dll and b/lib/net47/PowerShellYamlSerializer.dll differ diff --git a/lib/netstandard2.1/PowerShellYamlSerializer.dll b/lib/netstandard2.1/PowerShellYamlSerializer.dll index f126f2c..8021696 100644 Binary files a/lib/netstandard2.1/PowerShellYamlSerializer.dll and b/lib/netstandard2.1/PowerShellYamlSerializer.dll differ diff --git a/src/PowerShellYamlSerializer.cs b/src/PowerShellYamlSerializer.cs index 09b0616..8f1c53b 100644 --- a/src/PowerShellYamlSerializer.cs +++ b/src/PowerShellYamlSerializer.cs @@ -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) {