mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-06 06:11:45 +00:00
Convert ConfLocation fully over to properties
This commit is contained in:
@@ -153,6 +153,8 @@ namespace SabreTools.Data.Extensions
|
||||
return chip.Clone() as Chip;
|
||||
else if (self is Condition condition)
|
||||
return condition.Clone() as Condition;
|
||||
else if (self is ConfLocation confLocation)
|
||||
return confLocation.Clone() as ConfLocation;
|
||||
else if (self is Control control)
|
||||
return control.Clone() as Control;
|
||||
else if (self is DeviceRef deviceRef)
|
||||
@@ -192,10 +194,6 @@ namespace SabreTools.Data.Extensions
|
||||
cloneConfiguration.Mask = selfConfiguration.Mask;
|
||||
cloneConfiguration.Tag = selfConfiguration.Tag;
|
||||
}
|
||||
else if (self is ConfLocation selfConfLocation && clone is ConfLocation cloneConfLocation)
|
||||
{
|
||||
cloneConfLocation.Inverted = selfConfLocation.Inverted;
|
||||
}
|
||||
else if (self is ConfSetting selfConfSetting && clone is ConfSetting cloneConfSetting)
|
||||
{
|
||||
cloneConfSetting.Default = selfConfSetting.Default;
|
||||
|
||||
@@ -10,10 +10,9 @@ namespace SabreTools.Data.Models.Listxml
|
||||
[XmlAttribute("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <remarks>Numeric?</remarks>
|
||||
[Required]
|
||||
[XmlAttribute("number")]
|
||||
public string? Number { get; set; }
|
||||
public long? Number { get; set; }
|
||||
|
||||
/// <remarks>(yes|no) "no"</remarks>
|
||||
[XmlAttribute("inverted")]
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
[JsonObject("conflocation"), XmlRoot("conflocation")]
|
||||
public class ConfLocation : DatItem
|
||||
public class ConfLocation : DatItem, ICloneable, IEquatable<ConfLocation>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
@@ -13,15 +14,44 @@ namespace SabreTools.Data.Models.Metadata
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <remarks>string, possibly long</remarks>
|
||||
public const string NumberKey = "number";
|
||||
public long? Number { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public ConfLocation() => ItemType = ItemType.ConfLocation;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Clone()
|
||||
{
|
||||
var obj = new ConfLocation();
|
||||
|
||||
obj.Inverted = Inverted;
|
||||
obj.Name = Name;
|
||||
obj.Number = Number;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(ConfLocation? other)
|
||||
{
|
||||
// Null never matches
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
// Properties
|
||||
if (Inverted != other.Inverted)
|
||||
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 (Number != other.Number)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
{
|
||||
Inverted = true,
|
||||
Name = "name",
|
||||
[Data.Models.Metadata.ConfLocation.NumberKey] = "number",
|
||||
Number = 12345,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1217,7 +1217,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.NotNull(confLocation);
|
||||
Assert.True(confLocation.Inverted);
|
||||
Assert.Equal("name", confLocation.Name);
|
||||
Assert.Equal("number", confLocation.ReadString(Data.Models.Metadata.ConfLocation.NumberKey));
|
||||
Assert.Equal(12345, confLocation.Number);
|
||||
}
|
||||
|
||||
private static void ValidateConfSetting(ConfSetting? confSetting)
|
||||
|
||||
@@ -724,7 +724,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.NotNull(confLocation);
|
||||
Assert.True(confLocation.Inverted);
|
||||
Assert.Equal("name", confLocation.Name);
|
||||
Assert.Equal("number", confLocation.ReadString(Data.Models.Metadata.ConfLocation.NumberKey));
|
||||
Assert.Equal(12345, confLocation.Number);
|
||||
}
|
||||
|
||||
private static void ValidateMetadataConfSetting(Data.Models.Metadata.ConfSetting? confSetting)
|
||||
|
||||
@@ -16,16 +16,22 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
public override Data.Models.Metadata.ItemType ItemType
|
||||
=> Data.Models.Metadata.ItemType.ConfLocation;
|
||||
|
||||
public bool? Inverted
|
||||
{
|
||||
get => (_internal as Data.Models.Metadata.ConfLocation)?.Inverted;
|
||||
set => (_internal as Data.Models.Metadata.ConfLocation)?.Inverted = value;
|
||||
}
|
||||
|
||||
public string? Name
|
||||
{
|
||||
get => (_internal as Data.Models.Metadata.ConfLocation)?.Name;
|
||||
set => (_internal as Data.Models.Metadata.ConfLocation)?.Name = value;
|
||||
}
|
||||
|
||||
public bool? Inverted
|
||||
public long? Number
|
||||
{
|
||||
get => (_internal as Data.Models.Metadata.ConfLocation)?.Inverted;
|
||||
set => (_internal as Data.Models.Metadata.ConfLocation)?.Inverted = value;
|
||||
get => (_internal as Data.Models.Metadata.ConfLocation)?.Number;
|
||||
set => (_internal as Data.Models.Metadata.ConfLocation)?.Number = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -406,6 +406,9 @@ namespace SabreTools.Metadata.Filter
|
||||
case ConfLocation item when fieldName == "inverted":
|
||||
checkValue = item.Inverted.FromYesNo();
|
||||
return true;
|
||||
case ConfLocation item when fieldName == "number":
|
||||
checkValue = item.Number?.ToString();
|
||||
return true;
|
||||
|
||||
case ConfSetting item when fieldName == "default":
|
||||
checkValue = item.Default.FromYesNo();
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace SabreTools.Metadata
|
||||
}
|
||||
else if (self is ConfLocation selfConfLocation && other is ConfLocation otherConfLocation)
|
||||
{
|
||||
if (selfConfLocation.Inverted != otherConfLocation.Inverted)
|
||||
if (!selfConfLocation.Equals(otherConfLocation))
|
||||
return false;
|
||||
}
|
||||
else if (self is ConfSetting selfConfSetting && other is ConfSetting otherConfSetting)
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace SabreTools.Serialization.CrossModel.Test
|
||||
var conflocation = new Data.Models.Listxml.ConfLocation
|
||||
{
|
||||
Name = "name",
|
||||
Number = "XXXXXX",
|
||||
Number = 12345,
|
||||
Inverted = true,
|
||||
};
|
||||
|
||||
@@ -712,7 +712,7 @@ namespace SabreTools.Serialization.CrossModel.Test
|
||||
{
|
||||
Assert.NotNull(conflocation);
|
||||
Assert.Equal("name", conflocation.Name);
|
||||
Assert.Equal("XXXXXX", conflocation.Number);
|
||||
Assert.Equal(12345, conflocation.Number);
|
||||
Assert.Equal(true, conflocation.Inverted);
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace SabreTools.Serialization.CrossModel.Test
|
||||
var conflocation = new Data.Models.Listxml.ConfLocation
|
||||
{
|
||||
Name = "name",
|
||||
Number = "XXXXXX",
|
||||
Number = 12345,
|
||||
Inverted = true,
|
||||
};
|
||||
|
||||
@@ -706,7 +706,7 @@ namespace SabreTools.Serialization.CrossModel.Test
|
||||
{
|
||||
Assert.NotNull(conflocation);
|
||||
Assert.Equal("name", conflocation.Name);
|
||||
Assert.Equal("XXXXXX", conflocation.Number);
|
||||
Assert.Equal(12345, conflocation.Number);
|
||||
Assert.Equal(true, conflocation.Inverted);
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace SabreTools.Serialization.CrossModel.Test
|
||||
var conflocation = new Data.Models.Listxml.ConfLocation
|
||||
{
|
||||
Name = "name",
|
||||
Number = "XXXXXX",
|
||||
Number = 12345,
|
||||
Inverted = true,
|
||||
};
|
||||
|
||||
@@ -706,7 +706,7 @@ namespace SabreTools.Serialization.CrossModel.Test
|
||||
{
|
||||
Assert.NotNull(conflocation);
|
||||
Assert.Equal("name", conflocation.Name);
|
||||
Assert.Equal("XXXXXX", conflocation.Number);
|
||||
Assert.Equal(12345, conflocation.Number);
|
||||
Assert.Equal(true, conflocation.Inverted);
|
||||
}
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var confLocation = new ConfLocation
|
||||
{
|
||||
Name = item.Name,
|
||||
Number = item.ReadString(Data.Models.Metadata.ConfLocation.NumberKey),
|
||||
Number = item.Number,
|
||||
Inverted = item.Inverted,
|
||||
};
|
||||
return confLocation;
|
||||
|
||||
@@ -287,7 +287,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var confLocation = new Data.Models.Metadata.ConfLocation
|
||||
{
|
||||
Name = item.Name,
|
||||
[Data.Models.Metadata.ConfLocation.NumberKey] = item.Number,
|
||||
Number = item.Number,
|
||||
Inverted = item.Inverted,
|
||||
};
|
||||
return confLocation;
|
||||
|
||||
@@ -282,7 +282,7 @@ namespace SabreTools.Serialization.Readers.Test
|
||||
var conflocation = new Data.Models.Listxml.ConfLocation
|
||||
{
|
||||
Name = "name",
|
||||
Number = "XXXXXX",
|
||||
Number = 12345,
|
||||
Inverted = true,
|
||||
};
|
||||
|
||||
@@ -779,7 +779,7 @@ namespace SabreTools.Serialization.Readers.Test
|
||||
{
|
||||
Assert.NotNull(conflocation);
|
||||
Assert.Equal("name", conflocation.Name);
|
||||
Assert.Equal("XXXXXX", conflocation.Number);
|
||||
Assert.Equal(12345, conflocation.Number);
|
||||
Assert.Equal(true, conflocation.Inverted);
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ namespace SabreTools.Serialization.Readers.Test
|
||||
var conflocation = new Data.Models.Listxml.ConfLocation
|
||||
{
|
||||
Name = "name",
|
||||
Number = "XXXXXX",
|
||||
Number = 12345,
|
||||
Inverted = true,
|
||||
};
|
||||
|
||||
@@ -773,7 +773,7 @@ namespace SabreTools.Serialization.Readers.Test
|
||||
{
|
||||
Assert.NotNull(conflocation);
|
||||
Assert.Equal("name", conflocation.Name);
|
||||
Assert.Equal("XXXXXX", conflocation.Number);
|
||||
Assert.Equal(12345, conflocation.Number);
|
||||
Assert.Equal(true, conflocation.Inverted);
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ namespace SabreTools.Serialization.Readers.Test
|
||||
var conflocation = new Data.Models.Listxml.ConfLocation
|
||||
{
|
||||
Name = "name",
|
||||
Number = "XXXXXX",
|
||||
Number = 12345,
|
||||
Inverted = true,
|
||||
};
|
||||
|
||||
@@ -773,7 +773,7 @@ namespace SabreTools.Serialization.Readers.Test
|
||||
{
|
||||
Assert.NotNull(conflocation);
|
||||
Assert.Equal("name", conflocation.Name);
|
||||
Assert.Equal("XXXXXX", conflocation.Number);
|
||||
Assert.Equal(12345, conflocation.Number);
|
||||
Assert.Equal(true, conflocation.Inverted);
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace SabreTools.Serialization.Readers
|
||||
var obj = new ConfLocation();
|
||||
|
||||
obj.Name = reader.GetAttribute("name");
|
||||
obj.Number = reader.GetAttribute("number");
|
||||
obj.Number = NumberHelper.ConvertToInt64(reader.GetAttribute("number"));
|
||||
obj.Inverted = reader.GetAttribute("inverted").AsYesNo();
|
||||
|
||||
return obj;
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace SabreTools.Serialization.Readers
|
||||
var obj = new ConfLocation();
|
||||
|
||||
obj.Name = reader.GetAttribute("name");
|
||||
obj.Number = reader.GetAttribute("number");
|
||||
obj.Number = NumberHelper.ConvertToInt64(reader.GetAttribute("number"));
|
||||
obj.Inverted = reader.GetAttribute("inverted").AsYesNo();
|
||||
|
||||
return obj;
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace SabreTools.Serialization.Readers
|
||||
var obj = new ConfLocation();
|
||||
|
||||
obj.Name = reader.GetAttribute("name");
|
||||
obj.Number = reader.GetAttribute("number");
|
||||
obj.Number = NumberHelper.ConvertToInt64(reader.GetAttribute("number"));
|
||||
obj.Inverted = reader.GetAttribute("inverted").AsYesNo();
|
||||
|
||||
return obj;
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace SabreTools.Serialization.Writers
|
||||
writer.WriteStartElement("conflocation");
|
||||
|
||||
writer.WriteRequiredAttributeString("name", obj.Name);
|
||||
writer.WriteRequiredAttributeString("number", obj.Number);
|
||||
writer.WriteRequiredAttributeString("number", obj.Number?.ToString());
|
||||
writer.WriteOptionalAttributeString("inverted", obj.Inverted.FromYesNo());
|
||||
|
||||
writer.WriteEndElement();
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace SabreTools.Serialization.Writers
|
||||
writer.WriteStartElement("conflocation");
|
||||
|
||||
writer.WriteRequiredAttributeString("name", obj.Name);
|
||||
writer.WriteRequiredAttributeString("number", obj.Number);
|
||||
writer.WriteRequiredAttributeString("number", obj.Number?.ToString());
|
||||
writer.WriteOptionalAttributeString("inverted", obj.Inverted.FromYesNo());
|
||||
|
||||
writer.WriteEndElement();
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace SabreTools.Serialization.Writers
|
||||
writer.WriteStartElement("conflocation");
|
||||
|
||||
writer.WriteRequiredAttributeString("name", obj.Name);
|
||||
writer.WriteRequiredAttributeString("number", obj.Number);
|
||||
writer.WriteRequiredAttributeString("number", obj.Number?.ToString());
|
||||
writer.WriteOptionalAttributeString("inverted", obj.Inverted.FromYesNo());
|
||||
|
||||
writer.WriteEndElement();
|
||||
|
||||
Reference in New Issue
Block a user