private object ReadList(Type type, XContainer element) { object instance; Type elementType; if (type.IsArray) { instance = reflection.CreateInstance(type, element.Elements().Count()); elementType = type.GetElementType(); } else { instance = reflection.CreateInstance(type); elementType = type.GetGenericArguments()[0]; } int index = 0; var array = instance as Array; foreach (var value in element.Elements()) { var itemType = reflection.GetTypeFromXmlNamespace(value.Name.NamespaceName); object o = ReadObject(itemType ?? elementType, value); if (array != null) { array.SetValue(o, index); } else { reflection.InvokeAdd(instance, o); } index += 1; } return(instance); }