/// <summary> /// This reads and sets its state or attributes stored in a <c>XML</c> format /// with the given reader. /// </summary> /// <param name="reader"> /// The reader with which the <c>XML</c> attributes of this object are accessed. /// </param> /// <exception cref="ArgumentNullException"> /// If the <paramref name="reader"/> is <see langword="null"/>. /// </exception> public override void ReadXml(XmlReader reader) { BuildExceptions.NotNull(reader, "reader"); Debug.Assert(reader.NodeType == XmlNodeType.Element); if (reader.NodeType != XmlNodeType.Element) { return; } if (!String.Equals(reader.Name, TagName, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, String.Format( "The element name '{0}' does not match the expected '{1}'.", reader.Name, TagName)); return; } string tempText = reader.GetAttribute("name"); if (String.IsNullOrEmpty(tempText) || !String.Equals(tempText, ConfigurationName, StringComparison.OrdinalIgnoreCase)) { throw new BuildException(String.Format( "ReadXml: The current name '{0}' does not match the expected name '{1}'.", tempText, ConfigurationName)); } if (reader.IsEmptyElement) { return; } while (reader.Read()) { if ((reader.NodeType == XmlNodeType.Element) && String.Equals(reader.Name, "property", StringComparison.OrdinalIgnoreCase)) { switch (reader.GetAttribute("name").ToLower()) { case "enabled": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { this.Enabled = Convert.ToBoolean(tempText); } break; case "tabsize": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _tabSize = Convert.ToInt32(tempText); } break; case "showlinenumbers": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _showLineNumbers = Convert.ToBoolean(tempText); } break; case "showoutlining": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _showOutlining = Convert.ToBoolean(tempText); } break; case "highlightenabled": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _highlightEnabled = Convert.ToBoolean(tempText); } break; case "highlightmode": _highlightMode = reader.ReadString(); break; case "snippetseparator": _snippetSeparator = reader.ReadString(); break; case "snippetstorage": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _snippetStorage = BuildCacheStorageType.Parse(tempText); } break; default: // Should normally not reach here... throw new NotImplementedException(reader.GetAttribute("name")); } } else if (reader.NodeType == XmlNodeType.EndElement) { if (String.Equals(reader.Name, TagName, StringComparison.OrdinalIgnoreCase)) { break; } } } }
/// <summary> /// This reads and sets its state or attributes stored in a <c>XML</c> format /// with the given reader. /// </summary> /// <param name="reader"> /// The reader with which the <c>XML</c> attributes of this object are accessed. /// </param> /// <exception cref="ArgumentNullException"> /// If the <paramref name="reader"/> is <see langword="null"/>. /// </exception> public override void ReadXml(XmlReader reader) { BuildExceptions.NotNull(reader, "reader"); Debug.Assert(reader.NodeType == XmlNodeType.Element); if (reader.NodeType != XmlNodeType.Element) { return; } if (!String.Equals(reader.Name, TagName, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, String.Format( "The element name '{0}' does not match the expected '{1}'.", reader.Name, TagName)); return; } string tempText = reader.GetAttribute("name"); if (String.IsNullOrEmpty(tempText) || !String.Equals(tempText, ConfigurationName, StringComparison.OrdinalIgnoreCase)) { throw new BuildException(String.Format( "ReadXml: The current name '{0}' does not match the expected name '{1}'.", tempText, ConfigurationName)); } if (reader.IsEmptyElement) { return; } while (reader.Read()) { if ((reader.NodeType == XmlNodeType.Element) && String.Equals(reader.Name, "property", StringComparison.OrdinalIgnoreCase)) { switch (reader.GetAttribute("name").ToLower()) { case "enabled": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { this.Enabled = Convert.ToBoolean(tempText); } break; case "externallinkcaching": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _cacheLinks = Convert.ToBoolean(tempText); } break; case "externallinkstorage": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _linkStorage = BuildCacheStorageType.Parse(tempText); if (_linkStorage != BuildCacheStorageType.Memory && _linkStorage != BuildCacheStorageType.Database) { // If not one of the valid values, reset it... _linkStorage = BuildCacheStorageType.Database; } } break; default: // Should normally not reach here... throw new NotImplementedException(reader.GetAttribute("name")); } } else if (reader.NodeType == XmlNodeType.EndElement) { if (String.Equals(reader.Name, TagName, StringComparison.OrdinalIgnoreCase)) { break; } } } }