using System.Collections.Generic; using System.Xml.Serialization; using SabreTools.Core; using Newtonsoft.Json; namespace SabreTools.DatItems.Formats { /// /// Represents one ListXML confsetting or dipvalue /// [JsonObject("setting"), XmlRoot("setting")] public class Setting : DatItem { #region Fields /// /// Setting name /// [JsonProperty("name")] [XmlElement("name")] public string Name { get; set; } /// /// Setting value /// [JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)] [XmlElement("value")] public string Value { get; set; } /// /// Determines if the setting is default or not /// [JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)] [XmlElement("default")] public bool? Default { get; set; } [JsonIgnore] public bool DefaultSpecified { get { return Default != null; } } /// /// List of conditions on the setting /// [JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)] [XmlElement("conditions")] public List Conditions { get; set; } [JsonIgnore] public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } } #endregion #region Accessors /// public override string GetName() => Name; /// public override void SetName(string name) => Name = name; #endregion #region Constructors /// /// Create a default, empty Setting object /// public Setting() { Name = string.Empty; ItemType = ItemType.Setting; } #endregion #region Cloning Methods public override object Clone() { return new Setting() { ItemType = this.ItemType, DupeType = this.DupeType, Machine = this.Machine.Clone() as Machine, Source = this.Source.Clone() as Source, Remove = this.Remove, Name = this.Name, Value = this.Value, Default = this.Default, Conditions = this.Conditions, }; } #endregion #region Comparision Methods public override bool Equals(DatItem other) { // If we don't have a Setting, return false if (ItemType != other.ItemType) return false; // Otherwise, treat it as a Setting Setting newOther = other as Setting; // If the Setting information matches bool match = (Name == newOther.Name && Value == newOther.Value && Default == newOther.Default); if (!match) return match; // If the conditions match if (ConditionsSpecified) { foreach (Condition condition in Conditions) { match &= newOther.Conditions.Contains(condition); } } return match; } #endregion } }