Let's use objects

This commit is contained in:
Matt Nadareski
2020-08-21 15:31:19 -07:00
parent b01217cffb
commit 4d7a4373a9
11 changed files with 166 additions and 64 deletions

View File

@@ -0,0 +1,70 @@
/// <summary>
/// This holds all of the auxiliary types needed for proper parsing
/// </summary>
namespace SabreTools.Library.DatItems
{
#region Machine
#region ListXML
/// <summary>
/// Represents one ListXML info object
/// </summary>
public class ListXmlInfo
{
public string Name { get; set; }
public string Value { get; set; }
public ListXmlInfo(string name, string value)
{
Name = name;
Value = value;
}
}
#endregion
#region SoftwareList
/// <summary>
/// Represents one SoftwareList shared feature object
/// </summary>
public class SoftwareListSharedFeature
{
public string Name { get; set; }
public string Value { get; set; }
public SoftwareListSharedFeature(string name, string value)
{
Name = name;
Value = value;
}
}
#endregion
#endregion // Machine
#region DatItem
#region SoftwareList
/// <summary>
/// Represents one SoftwareList feature object
/// </summary>
public class SoftwareListFeature
{
public string Name { get; set; }
public string Value { get; set; }
public SoftwareListFeature(string name, string value)
{
Name = name;
Value = value;
}
}
#endregion
#endregion //DatItem
}

View File

@@ -87,7 +87,7 @@ namespace SabreTools.Library.DatItems
/// Features provided to/by the item
/// </summary>
[JsonProperty("features")]
public List<KeyValuePair<string, string>> Features { get; set; }
public List<SoftwareListFeature> Features { get; set; }
/// <summary>
/// Original hardware part name within an item
@@ -296,7 +296,7 @@ namespace SabreTools.Library.DatItems
fieldValue = PartInterface;
break;
case Field.Features:
fieldValue = string.Join(";", (Features ?? new List<KeyValuePair<string, string>>()).Select(f => $"{f.Key}={f.Value}"));
fieldValue = string.Join(";", (Features ?? new List<SoftwareListFeature>()).Select(f => $"{f.Name}={f.Value}"));
break;
case Field.AreaName:
fieldValue = AreaName;
@@ -366,13 +366,13 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.Features))
{
if (Features == null)
Features = new List<KeyValuePair<string, string>>();
Features = new List<SoftwareListFeature>();
string[] pairs = mappings[Field.Features].Split(';');
foreach (string pair in pairs)
{
string[] split = pair.Split('=');
Features.Add(new KeyValuePair<string, string>(split[0], split[1]));
Features.Add(new SoftwareListFeature(split[0], split[1]));
}
}

View File

@@ -167,7 +167,7 @@ namespace SabreTools.Library.DatItems
/// </summary>
/// <remarks>Also in SoftwareList</remarks>
[JsonProperty("infos")]
public List<KeyValuePair<string, string>> Infos { get; set; } = null;
public List<ListXmlInfo> Infos { get; set; } = null;
#endregion
@@ -259,7 +259,7 @@ namespace SabreTools.Library.DatItems
/// </summary>
/// <remarks>Also in SoftwareList</remarks>
[JsonProperty("sharedfeat")]
public List<KeyValuePair<string, string>> SharedFeatures { get; set; } = null;
public List<SoftwareListSharedFeature> SharedFeatures { get; set; } = null;
#endregion
@@ -358,7 +358,7 @@ namespace SabreTools.Library.DatItems
fieldValue = string.Join(";", SlotOptions ?? new List<string>());
break;
case Field.Infos:
fieldValue = string.Join(";", (Infos ?? new List<KeyValuePair<string, string>>()).Select(i => $"{i.Key}={i.Value}"));
fieldValue = string.Join(";", (Infos ?? new List<ListXmlInfo>()).Select(i => $"{i.Name}={i.Value}"));
break;
#endregion
@@ -412,7 +412,7 @@ namespace SabreTools.Library.DatItems
fieldValue = Supported?.ToString();
break;
case Field.SharedFeatures:
fieldValue = string.Join(";", (SharedFeatures ?? new List<KeyValuePair<string, string>>()).Select(i => $"{i.Key}={i.Value}"));
fieldValue = string.Join(";", (SharedFeatures ?? new List<SoftwareListSharedFeature>()).Select(i => $"{i.Name}={i.Value}"));
break;
#endregion
@@ -525,13 +525,13 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.Infos))
{
if (Infos == null)
Infos = new List<KeyValuePair<string, string>>();
Infos = new List<ListXmlInfo>();
string[] pairs = mappings[Field.Infos].Split(';');
foreach (string pair in pairs)
{
string[] split = pair.Split('=');
Infos.Add(new KeyValuePair<string, string>(split[0], split[1]));
Infos.Add(new ListXmlInfo(split[0], split[1]));
}
}
@@ -586,13 +586,13 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.SharedFeatures))
{
if (SharedFeatures == null)
SharedFeatures = new List<KeyValuePair<string, string>>();
SharedFeatures = new List<SoftwareListSharedFeature>();
string[] pairs = mappings[Field.SharedFeatures].Split(';');
foreach (string pair in pairs)
{
string[] split = pair.Split('=');
SharedFeatures.Add(new KeyValuePair<string, string>(split[0], split[1]));
SharedFeatures.Add(new SoftwareListSharedFeature(split[0], split[1]));
}
}