private void WriteSettingObjectRecursively(System.Xml.Linq.XElement element, SettingItemBase settingItem) { if (settingItem is SettingItemGroup) { var settingItemGroup = settingItem as SettingItemGroup; if (settingItemGroup.HasAttributes) { foreach (var attr in settingItemGroup.Attributes) { element.Add(new System.Xml.Linq.XAttribute(attr.Name, attr.Value)); } } } if (settingItem.HasChildren) { bool hasChildren = false; foreach (var child in settingItem.Children) { hasChildren = child.HasChildren; var xElement = hasChildren ? new System.Xml.Linq.XElement(child.Name) : new System.Xml.Linq.XElement(child.Name, child.Value); element.Add(xElement); this.WriteSettingObjectRecursively(xElement, child); } } }
/// <summary> /// Compares the value and name of current setting with another setting. /// </summary> /// <param name="obj">The instance of type <see cref="SettingItem"/> to compare</param> /// <returns></returns> public override bool Equals(object obj) { if (obj == null || !typeof(SettingItemBase).GetTypeInfo().IsAssignableFrom(obj.GetType().GetTypeInfo())) { return(false); } SettingItemBase settingToCompare = (SettingItemBase)obj; bool isEqual = string.Equals(this.Name, settingToCompare.Name, StringComparison.CurrentCultureIgnoreCase) && string.Equals(this.Value, settingToCompare.Value, StringComparison.CurrentCultureIgnoreCase); return(isEqual); }
/// <summary> /// Adds a setting item or attribute item into the group /// </summary> /// <param name="child">Item to add</param> public override void Add(SettingItemBase child) { if (child == null) { return; } if (child is SettingAttributeItem) { var attr = this.GetAttribute(child.Name); if (attr == null) { this.attributes.Add(child); } else { attr.Value = child.Value; } } else if (child is SettingItemGroup) { SettingItemBase uniqueKeyAttr = null; IEnumerable <SettingItemBase> attributes = null; SettingItemGroup itemGroup = child as SettingItemGroup; uniqueKeyAttr = itemGroup.GetAttribute(CONST.SETTING_UNIQUE_KEY_ATTRIBUTE); attributes = itemGroup.Attributes; SettingItemBase foundChild = uniqueKeyAttr != null ? this.GetChild(child.Name, uniqueKeyAttr.Value) : this.GetChild(child.Name); if (foundChild == null) { this.children.Add(child); } else { foundChild.Value = child.Value; if (attributes != null) { foreach (var attr in attributes) { foundChild.Add(attr); } } } } }
/// <summary> /// Adds a setting item or attribute item into the group /// </summary> /// <param name="child">Item to add</param> public virtual void Add(SettingItemBase child) { }