/// <summary> /// Using childNodes from an element, deserialize an array by deserializing the /// individual elements into the array elements. /// </summary> /// <param name="_xml"> /// The XML parent node containing the array elements as childNodes /// </param> /// <param name="_arrayHelper">The ArrayDeserializationHelper</param> private void DeserializeArrayFromElements(XmlElement _xml, CArrayDeserializationHelper _arrayHelper) { foreach (XmlNode node in _xml.ChildNodes) { if (!(node is XmlElement elem)) { throw new XDeserializationError(node.NodeType.ToString() + " was the nodetype found (instead of XmlElement) as a child of the array's XML"); } int[] indicies = null; var sIndex = XmlExtensions.GetAttributeValue(elem, m_context.ArrayIndexAttributeName); if (sIndex != null) { indicies = sIndex.Split(',').Select(s => int.Parse(s)).ToArray(); } if (indicies != null && indicies.Length > 0) { _arrayHelper.SetIndicies(indicies); } var obj = FrameworkDeserialize(elem, _arrayHelper.ElementType); _arrayHelper.Add(obj); } }
/// <summary> /// Using the info in a "condensed array", deserialize an Array into an object. /// </summary> /// <param name="_condensedArray"> /// The "Condensed Array"- a string[] containing data from a CSV list /// </param> /// <param name="_arrayHelper">The ArrayDeserializationHelper</param> private static void DeserializeArrayFromCondensedArray(string[] _condensedArray, CArrayDeserializationHelper _arrayHelper) { var elemType = _arrayHelper.ElementType; foreach (var s in _condensedArray) { if (elemType == TYPEOF_STRING) { var str = UnprotectStringFromStringlist(s); _arrayHelper.Add(str); } else if (elemType.IsPrimitive) { var obj = Convert.ChangeType(s, elemType); _arrayHelper.Add(obj); } else { throw new XDeserializationError( "A single XmlText node was found, but the ElementType is complex- " + elemType.ToString()); } } }