Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Moryx/Serialization/EntryConvert/EntryConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public static Entry EncodeObject(object instance, ICustomSerialization customSer
{
//exclude property that can lead to self reference
var propertyType = property.PropertyType;
if (propertyType == instanceType)
if (propertyType == instanceType || propertyType.IsAssignableFrom(instanceType))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,12 @@ public class AlwaysAttributedDerivedType : NeverAttributedBaseType

public bool NullProperty3 { get; set; }
}

public class SelfReferencingBase
{
public SelfReferencingBase Self { get; set; }
}

public class SelfReferencingDerived : SelfReferencingBase
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,13 @@ public void ClassWithSerializationAttribute()
var alwaysProperties = 3;
Assert.That(alwaysProperties, Is.EqualTo(encoded.SubEntries.Count));
}

[Test]
public void SerializeClassWithSelfReference()
{
var instance = new SelfReferencingDerived();
instance.Self = instance;
Assert.DoesNotThrow(() => EntryConvert.EncodeObject(instance));
}
}

Loading