Skip to content

Commit

Permalink
Form data - serializing arrays and not only List<>
Browse files Browse the repository at this point in the history
  • Loading branch information
napernik committed Dec 14, 2015
1 parent 8df5fbd commit 7bbd43c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Composite/Core/Serialization/SystemCollectionValueXmlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,28 @@ public bool TrySerialize(Type objectToSerializeType, object objectToSerialize, I

serializedObject = null;

if (objectToSerializeType.IsGenericType == false) return false;

bool isArray = objectToSerializeType.IsArray;
if (!objectToSerializeType.IsGenericType && !isArray) return false;

if (isArray)
{
objectToSerializeType = objectToSerializeType.GetInterfaces()
.FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof (ICollection<>));

if (objectToSerializeType == null)
{
return false;
}
}

Type genericType = objectToSerializeType.GetGenericTypeDefinition();

MethodInfo methodInfo;

if (genericType == typeof(List<>))
if (genericType == typeof(List<>) || genericType == typeof(ICollection<>))
{
methodInfo = StaticReflection.GetGenericMethodInfo(o => SerializeList<object>(null, null));
methodInfo = StaticReflection.GetGenericMethodInfo(o => SerializeCollection<object>(null, null));
}
else if (genericType == typeof(Dictionary<,>))
{
Expand Down Expand Up @@ -119,7 +132,7 @@ public bool TryDeserialize(XElement serializedObject, IXmlSerializer xmlSerializ



private static XElement SerializeList<T>(List<T> listToSerialize, IXmlSerializer xmlSerializer)
private static XElement SerializeCollection<T>(ICollection<T> listToSerialize, IXmlSerializer xmlSerializer)
{
XElement result = new XElement("List");

Expand Down

0 comments on commit 7bbd43c

Please sign in to comment.