mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-24 15:55:05 +00:00
Convert subitems for Configuration and DipSwitch
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
[JsonObject("configuration"), XmlRoot("configuration")]
|
||||
public class Configuration : DatItem
|
||||
public class Configuration : DatItem, ICloneable, IEquatable<Configuration>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
public ConfLocation[]? ConfLocation { get; set; }
|
||||
|
||||
public ConfSetting[]? ConfSetting { get; set; }
|
||||
|
||||
public string? Mask { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
@@ -18,18 +23,57 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <remarks>ConfLocation[]</remarks>
|
||||
[NoFilter]
|
||||
public const string ConfLocationKey = "conflocation";
|
||||
|
||||
/// <remarks>ConfSetting[]</remarks>
|
||||
[NoFilter]
|
||||
public const string ConfSettingKey = "confsetting";
|
||||
|
||||
#endregion
|
||||
|
||||
public Configuration() => ItemType = ItemType.Configuration;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Clone()
|
||||
{
|
||||
var obj = new Configuration();
|
||||
|
||||
obj.Condition = Condition?.Clone() as Condition;
|
||||
if (ConfLocation is not null)
|
||||
obj.ConfLocation = Array.ConvertAll(ConfLocation, i => (ConfLocation)i.Clone());
|
||||
if (ConfSetting is not null)
|
||||
obj.ConfSetting = Array.ConvertAll(ConfSetting, i => (ConfSetting)i.Clone());
|
||||
obj.Mask = Mask;
|
||||
obj.Name = Name;
|
||||
obj.Tag = Tag;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(Configuration? other)
|
||||
{
|
||||
// Null never matches
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
// Properties
|
||||
if ((Mask is null) ^ (other.Mask is null))
|
||||
return false;
|
||||
else if (Mask is not null && !Mask.Equals(other.Mask, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Name is null) ^ (other.Name is null))
|
||||
return false;
|
||||
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
if ((Tag is null) ^ (other.Tag is null))
|
||||
return false;
|
||||
else if (Tag is not null && !Tag.Equals(other.Tag, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
// Sub-items
|
||||
if ((Condition is null) ^ (other.Condition is null))
|
||||
return false;
|
||||
else if (Condition is not null && other.Condition is not null && Condition.Equals(other.Condition))
|
||||
return false;
|
||||
|
||||
// TODO: Figure out how to properly check arrays
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user