public void VerifyEnumeration() { foreach (XmlNode node in XmlElementList.Create(XmlDocumentResource.ElementListWithComment.ChildNodes)) { Assert.IsNotNull(node); } }
protected override object Read(XmlNode node, Type instanceType, NetReflectorTypeTable table) { Type elementType = instanceType.GetElementType(); // null check XmlElementList nodes = new XmlElementList(node.ChildNodes); Array array = Array.CreateInstance(elementType, nodes.Count); for (int i = 0; i < array.Length; i++) { try { object value = converter.Convert(elementType, ReadValue(nodes[i], table)); if (value == null) { throw new NetReflectorConverterException( string.Format("Unable to convert element '{0}' to '{1}'", nodes[i].Name, elementType.FullName)); } array.SetValue(value, i); } catch (NetReflectorConverterException error) { throw new NetReflectorException( string.Format("Unable to load array item '{0}' - {1}" + Environment.NewLine + "Xml: {2}", nodes[i].Name, error.Message, nodes[i].OuterXml), error); } } return(array); }
protected override object Read(XmlNode node, Type instanceType, NetReflectorTypeTable table) { Type elementType = instanceType.GetElementType(); // null check XmlElementList nodes = new XmlElementList(node.ChildNodes); Array array = Array.CreateInstance(elementType, nodes.Count); for (int i = 0; i < array.Length; i++) { try { object value = converter.Convert(elementType, ReadValue(nodes[i], table)); if (value == null) { throw new NetReflectorConverterException( string.Format("Unable to convert element '{0}' to '{1}'", nodes[i].Name, elementType.FullName)); } array.SetValue(value, i); } catch (NetReflectorConverterException error) { throw new NetReflectorException( string.Format("Unable to load array item '{0}' - {1}" + Environment.NewLine + "Xml: {2}", nodes[i].Name, error.Message, nodes[i].OuterXml), error); } } return array; }
public void EnsureNodeListHandlesComments() { XmlNode node = XmlDocumentResource.ElementListWithComment; Assert.AreEqual(3, node.ChildNodes.Count); XmlElementList list = new XmlElementList(node.ChildNodes); Assert.AreEqual(2, list.Count); Assert.AreEqual("hashitem1", list[0].Attributes["id"].Value); Assert.AreEqual("hashitem3", list[1].Attributes["id"].Value); }
protected override object Read(XmlNode node, Type instanceType, NetReflectorTypeTable table) { IDictionary dictionary = Instantiator.Instantiate(instanceType) as IDictionary; // null check foreach (XmlNode child in XmlElementList.Create(node.ChildNodes)) { object key = GetHashkey(child); object value = base.ReadValue(child, table); dictionary.Add(key, value); } return(dictionary); }
/// Todo: convert to element type protected override object Read(XmlNode node, Type instanceType, NetReflectorTypeTable table) { IList list = Instantiator.Instantiate(instanceType) as IList; // null check foreach (XmlNode child in XmlElementList.Create(node.ChildNodes)) { object value = base.ReadValue(child, table); try { list.Add(value); } catch (InvalidCastException error) { throw new NetReflectorConverterException( string.Format("Unable to convert element '{0}' to its required type{2}XML: {1}", child.Name, node.OuterXml, Environment.NewLine), error); } } return(list); }