public void ReadXml() { string xml = "<extension name=\"test\" version=\"1.0.0\"><class></class></extension>"; ExtensionInfo info = new ExtensionInfo(); XmlReader reader = XmlReader.Create(new System.IO.StringReader(xml)); while (!reader.IsStartElement()) { reader.Read(); } info.ReadXml(reader); Assert.AreEqual("test", info.Name); Assert.AreEqual(new Version("1.0.0"), info.Version); Assert.IsNull(info.Author); Assert.IsNull(info.Description); Assert.IsNull(info.Dependencies); Assert.IsEmpty(info.Class); xml = "<extension version=\"1.0\" name=\"My displayed name\"><class>the full qualified name of the class implementing the extension</class><author>Someone</author><dependencies><dependency>a fullname to the extension</dependency><dependency>a second extension</dependency></dependencies></extension>"; reader = XmlReader.Create(new System.IO.StringReader(xml)); while (!reader.IsStartElement()) { reader.Read(); } info = new ExtensionInfo(); info.ReadXml(reader); Assert.AreEqual("My displayed name", info.Name); Assert.AreEqual(new Version("1.0"), info.Version); Assert.IsNull(info.Description); Assert.AreEqual("a fullname to the extension", info.Dependencies[0]); Assert.AreEqual("a second extension", info.Dependencies[1]); Assert.AreEqual(info.Class, "the full qualified name of the class implementing the extension"); }
/// <summary> /// Reads the list of loaded extensions. /// </summary> /// <param name="reader">The reader to read from.</param> private void ReadLoadedExtensions(XmlReader reader) { reader.Read(); while (true) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name) { case "extension": try { ExtensionInfo info = new ExtensionInfo(); info.ReadXml(reader); loadedExtensions.Add(info); } catch (Exception ex) { throw new ConfigurationException("couldn't load extension info", ex); } break; default: reader.Skip(); break; } break; case XmlNodeType.EndElement: reader.Read(); return; default: if (!reader.Read()) { return; } break; } } }