using System.Collections.Generic; using Newtonsoft.Json.Linq; namespace EDJournal { public class Killer { private string name; private string rank; private string ship; public string Name { get => name; set => name = value; } public string Rank { get => rank; set => rank = value; } public string Ship { get => ship; set => ship = value; } } public class DiedEntry : Entry { private readonly List killers = new List(); public List Killers => killers; public Killer Killer => killers.Count > 0 ? killers[0] : null; public bool WasWing => killers.Count > 1; protected override void Initialise() { var wing = JSON.Value("Killers"); if (wing != null) { /* a wing killed us */ foreach (JObject child in wing.Children()) { Killer killer = new Killer { Name = child.Value("Name") ?? "", Rank = child.Value("Rank") ?? "", Ship = child.Value("Ship") ?? "" }; killers.Add(killer); } } else { /* a single ship killed us */ Killer killer = new Killer { Name = JSON.Value("KillerName") ?? "", Rank = JSON.Value("KillerRank") ?? "", Ship = JSON.Value("KillerShip") ?? "" }; killers.Add(killer); } } } }