Files
SabreTools/SabreTools.DatItems/Formats/Info.cs

102 lines
2.5 KiB
C#
Raw Normal View History

using System.Xml.Serialization;
2020-09-03 13:20:56 -07:00
using Newtonsoft.Json;
2022-11-03 12:22:17 -07:00
using SabreTools.Core;
2020-09-02 23:31:35 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
2020-09-02 23:31:35 -07:00
{
/// <summary>
/// Represents special information about a machine
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("info"), XmlRoot("info")]
2020-09-02 23:31:35 -07:00
public class Info : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("name"), XmlElement("name")]
public string? Name
{
get => _info.ReadString(Models.Internal.Info.NameKey);
set => _info[Models.Internal.Info.NameKey] = value;
}
2020-09-02 23:31:35 -07:00
/// <summary>
/// Information value
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("value"), XmlElement("value")]
public string? Value
{
get => _info.ReadString(Models.Internal.Info.ValueKey);
set => _info[Models.Internal.Info.ValueKey] = value;
}
/// <summary>
/// Internal Info model
/// </summary>
[JsonIgnore]
private Models.Internal.Info _info = new();
2020-09-02 23:31:35 -07:00
#endregion
#region Accessors
/// <inheritdoc/>
public override string? GetName() => Name;
2020-09-02 23:31:35 -07:00
/// <inheritdoc/>
public override void SetName(string? name) => Name = name;
2020-09-02 23:31:35 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Info object
/// </summary>
public Info()
{
Name = string.Empty;
ItemType = ItemType.Info;
}
#endregion
#region Cloning Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2020-09-02 23:31:35 -07:00
public override object Clone()
{
return new Info()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine?.Clone() as Machine,
Source = this.Source?.Clone() as Source,
2020-09-02 23:31:35 -07:00
Remove = this.Remove,
_info = this._info?.Clone() as Models.Internal.Info ?? new Models.Internal.Info(),
2020-09-02 23:31:35 -07:00
};
}
#endregion
#region Comparision Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
public override bool Equals(DatItem? other)
2020-09-02 23:31:35 -07:00
{
// If we don't have a Info, return false
if (ItemType != other?.ItemType || other is not Info otherInternal)
2020-09-02 23:31:35 -07:00
return false;
// Compare the internal models
return _info.EqualTo(otherInternal._info);
2020-09-02 23:31:35 -07:00
}
#endregion
}
}