public static GetIndexerProperty ( |
||
collectionType | ||
return |
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"); } }
private void WriteListContent(object container, TypeData listType, ListMap map, object ob, StringBuilder targetString) { if (listType.Type.IsArray) { Array array = (Array)ob; for (int i = 0; i < array.Length; i++) { object value = array.GetValue(i); XmlTypeMapElementInfo xmlTypeMapElementInfo = map.FindElement(container, i, value); if (xmlTypeMapElementInfo != null && targetString == null) { this.WriteMemberElement(xmlTypeMapElementInfo, value); } else if (xmlTypeMapElementInfo != null && targetString != null) { targetString.Append(this.GetStringValue(xmlTypeMapElementInfo.MappedType, xmlTypeMapElementInfo.TypeData, value)).Append(" "); } else if (value != null) { throw base.CreateUnknownTypeException(value); } } } else if (ob is ICollection) { int num = (int)ob.GetType().GetProperty("Count").GetValue(ob, null); PropertyInfo indexerProperty = TypeData.GetIndexerProperty(listType.Type); object[] array2 = new object[1]; for (int j = 0; j < num; j++) { array2[0] = j; object value2 = indexerProperty.GetValue(ob, array2); XmlTypeMapElementInfo xmlTypeMapElementInfo2 = map.FindElement(container, j, value2); if (xmlTypeMapElementInfo2 != null && targetString == null) { this.WriteMemberElement(xmlTypeMapElementInfo2, value2); } else if (xmlTypeMapElementInfo2 != null && targetString != null) { targetString.Append(this.GetStringValue(xmlTypeMapElementInfo2.MappedType, xmlTypeMapElementInfo2.TypeData, value2)).Append(" "); } else if (value2 != null) { throw base.CreateUnknownTypeException(value2); } } } else { if (!(ob is IEnumerable)) { throw new Exception("Unsupported collection type"); } IEnumerable enumerable = (IEnumerable)ob; foreach (object obj in enumerable) { XmlTypeMapElementInfo xmlTypeMapElementInfo3 = map.FindElement(container, -1, obj); if (xmlTypeMapElementInfo3 != null && targetString == null) { this.WriteMemberElement(xmlTypeMapElementInfo3, obj); } else if (xmlTypeMapElementInfo3 != null && targetString != null) { targetString.Append(this.GetStringValue(xmlTypeMapElementInfo3.MappedType, xmlTypeMapElementInfo3.TypeData, obj)).Append(" "); } else if (obj != null) { throw base.CreateUnknownTypeException(obj); } } } }