void WriteListContent (object container, TypeData listType, ListMap map, object ob, StringBuilder targetString)
{
if (listType.Type.IsArray)
{
Array array = (Array)ob;
for (int n=0; n<array.Length; n++)
{
object item = array.GetValue (n);
XmlTypeMapElementInfo info = map.FindElement (container, n, item);
if (info != null && targetString == null) WriteMemberElement (info, item);
else if (info != null && targetString != null) targetString.Append (GetStringValue (info.MappedType, info.TypeData, item)).Append (" ");
else if (item != null) throw CreateUnknownTypeException (item);
}
}
else if (ob is ICollection)
{
int count = (int) ob.GetType().GetProperty ("Count").GetValue(ob,null);
PropertyInfo itemProp = TypeData.GetIndexerProperty (listType.Type);
object[] index = new object[1];
for (int n=0; n<count; n++)
{
index[0] = n;
object item = itemProp.GetValue (ob, index);
XmlTypeMapElementInfo info = map.FindElement (container, n, item);
if (info != null && targetString == null) WriteMemberElement (info, item);
else if (info != null && targetString != null) targetString.Append (GetStringValue (info.MappedType, info.TypeData, item)).Append (" ");
else if (item != null) throw CreateUnknownTypeException (item);
}
}
else if (ob is IEnumerable)
{
IEnumerable e = (IEnumerable)ob;
foreach (object item in e)
{
XmlTypeMapElementInfo info = map.FindElement (container, -1, item);
if (info != null && targetString == null) WriteMemberElement (info, item);
else if (info != null && targetString != null) targetString.Append (GetStringValue (info.MappedType, info.TypeData, item)).Append (" ");
else if (item != null) throw CreateUnknownTypeException (item);
}
}
else
throw new Exception ("Unsupported collection type");
}