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

Commit 325d295

Browse files
committed
Merge pull request #361 from WimAtIHomer/master
Added XmlElement test and possible fixes to fix test
2 parents 9cb0a0a + 607bc95 commit 325d295

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

src/ServiceStack.Text/Common/DeserializeSpecializedCollections.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static ParseStringDelegate GetParseFn()
5252
return ParseStringCollection<TSerializer>;
5353
}
5454
#endif
55-
if (typeof(T) == typeof(IEnumerable))
55+
if (typeof (T) == typeof (IEnumerable) || typeof(T) == typeof(ICollection))
5656
{
5757
return GetEnumerableParseFn();
5858
}
@@ -139,6 +139,7 @@ public static ParseStringDelegate GetEnumerableParseFn()
139139
public static ParseStringDelegate GetGenericEnumerableParseFn()
140140
{
141141
var enumerableInterface = typeof(T).GetTypeWithGenericInterfaceOf(typeof(IEnumerable<>));
142+
if (enumerableInterface == null) return null;
142143
var elementType = enumerableInterface.GenericTypeArguments()[0];
143144
var genericType = typeof(SpecializedEnumerableElements<,>).MakeGenericType(typeof(T), elementType);
144145
var fi = genericType.GetPublicStaticField("ConvertFn");
@@ -213,4 +214,4 @@ public static object ConvertFromCollection(object enumerable)
213214
return to;
214215
}
215216
}
216-
}
217+
}

src/ServiceStack.Text/Common/JsReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private ParseStringDelegate GetCoreParseFn<T>()
8585
}
8686
#endif
8787

88-
var isDictionary = typeof(T) != typeof(IEnumerable)
88+
var isDictionary = typeof(T) != typeof(IEnumerable) && typeof(T) != typeof(ICollection)
8989
&& (typeof(T).AssignableFrom(typeof(IDictionary)) || typeof(T).HasInterface(typeof(IDictionary)));
9090
if (isDictionary)
9191
{
@@ -124,4 +124,4 @@ private ParseStringDelegate GetCoreParseFn<T>()
124124
}
125125

126126
}
127-
}
127+
}

src/ServiceStack.Text/Common/JsWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ private WriteObjectDelegate GetCoreWriteFn<T>()
413413
}
414414
}
415415

416-
var isDictionary = typeof(T) != typeof(IEnumerable)
416+
var isDictionary = typeof(T) != typeof(IEnumerable) && typeof(T) != typeof(ICollection)
417417
&& (typeof(T).AssignableFrom(typeof(IDictionary)) || typeof(T).HasInterface(typeof(IDictionary)));
418418
if (isDictionary)
419419
{
@@ -462,4 +462,4 @@ public void WriteType(TextWriter writer, object value)
462462
}
463463

464464
}
465-
}
465+
}

tests/ServiceStack.Text.Tests/AdhocModelTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Globalization;
66
using System.Runtime.Serialization;
77
using System.Threading;
8+
using System.Xml;
89
using NUnit.Framework;
910
using ServiceStack.Common.Extensions;
1011
using ServiceStack.Text.Jsv;
@@ -710,7 +711,39 @@ public void Can_serialize_IEnumerable()
710711
};
711712

712713
var from = Serialize(dto, includeXml: false);
714+
Assert.IsNotNull(from.Blah);
713715
from.PrintDump();
714716
}
717+
718+
public class BreakerCollection
719+
{
720+
public ICollection Blah { get; set; }
721+
}
722+
723+
[Test]
724+
public void Can_serialize_ICollection()
725+
{
726+
var dto = new BreakerCollection
727+
{
728+
Blah = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }
729+
};
730+
731+
var from = Serialize(dto, includeXml: false);
732+
Assert.IsNotNull(from.Blah);
733+
Assert.AreEqual(dto.Blah.Count, from.Blah.Count);
734+
from.PrintDump();
735+
}
736+
737+
public class XmlAny
738+
{
739+
public XmlElement[] Any { get; set; }
740+
}
741+
742+
[Test]
743+
public void Can_serialize_Specialized_IEnumerable()
744+
{
745+
var getParseFn = JsvReader.GetParseFn(typeof (XmlAny));
746+
Assert.IsNotNull(getParseFn);
747+
}
715748
}
716749
}

0 commit comments

Comments
 (0)