Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit f455d0b

Browse files
committed
Add fix for Dump on cyclical refs with IEnumerables
1 parent 6f5a7f5 commit f455d0b

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

lib/ServiceStack.Client.dll

0 Bytes
Binary file not shown.

lib/ServiceStack.Common.dll

0 Bytes
Binary file not shown.

lib/ServiceStack.Interfaces.dll

0 Bytes
Binary file not shown.

lib/tests/ServiceStack.Interfaces.dll

0 Bytes
Binary file not shown.

src/ServiceStack.Text/ReflectionExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212

1313
using System;
14+
using System.Collections;
1415
using System.Collections.Concurrent;
1516
using System.Collections.Generic;
1617
using System.ComponentModel;
@@ -2001,7 +2002,15 @@ public static Dictionary<string, object> ToSafePartialObjectDictionary<T>(this T
20012002
}
20022003
else if (!TypeSerializer.HasCircularReferences(entry.Value))
20032004
{
2004-
to[entry.Key] = entry.Value.ToSafePartialObjectDictionary();
2005+
var enumerable = entry.Value as IEnumerable;
2006+
if (enumerable != null)
2007+
{
2008+
to[entry.Key] = entry.Value;
2009+
}
2010+
else
2011+
{
2012+
to[entry.Key] = entry.Value.ToSafePartialObjectDictionary();
2013+
}
20052014
}
20062015
else
20072016
{

tests/ServiceStack.Text.Tests/DumpTests.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using System;
2+
using NUnit.Framework;
23

34
namespace ServiceStack.Text.Tests
45
{
@@ -36,7 +37,7 @@ public void Can_detect_Circular_References_in_models()
3637
}
3738

3839
[Test]
39-
public void Can_PrintDump_ToSafeJson_ToSafeJsv()
40+
public void Can_PrintDump_ToSafeJson_ToSafeJsv_recursive_Node()
4041
{
4142
var node = new Node(1,
4243
new Node(11, new Node(111)),
@@ -53,5 +54,29 @@ public void Can_PrintDump_ToSafeJson_ToSafeJsv()
5354
root.ToSafeJson().Print();
5455
root.ToSafeJsv().Print();
5556
}
57+
58+
public class CustomExecption : Exception
59+
{
60+
public string[] CustomData { get; set; }
61+
}
62+
63+
[Test]
64+
public void Can_PrintDump_ToSafeJson_ToSafeJsv_Exception()
65+
{
66+
try
67+
{
68+
throw new ArgumentException("param",
69+
new CustomExecption
70+
{
71+
CustomData = new[] { "A", "B", "C"}
72+
});
73+
}
74+
catch (Exception ex)
75+
{
76+
ex.PrintDump();
77+
ex.ToSafeJson().Print();
78+
ex.ToSafeJsv().Print();
79+
}
80+
}
5681
}
5782
}

0 commit comments

Comments
 (0)