private ICollection <PerpetratorData> ModifyPerpetrators(JToken json) { var perpetrators = new List <PerpetratorData>(); foreach (var perpetratorJson in json) { var perpetrator = new PerpetratorData { Name = perpetratorJson.Value <string>("name"), Clothing = perpetratorJson.Value <string>("clothing"), MinimumAge = perpetratorJson.Value <int>("minimumAge"), MaximumAge = perpetratorJson.Value <int>("maximumAge"), UniqueProperties = perpetratorJson.Value <string>("uniqueProperties") }; var textInfo = new CultureInfo("en-US", false).TextInfo; var sex = perpetratorJson["sex"] != null?textInfo.ToTitleCase(perpetratorJson.Value <string>("sex")) : null; var skinColor = perpetratorJson["skinColor"] != null?textInfo.ToTitleCase(perpetratorJson.Value <string>("skinColor")) : null; perpetrator.SkinColor = skinColor != null ? (SkinColorEnum)Enum.Parse(typeof(SkinColorEnum), skinColor, true) : SkinColorEnum.Unknown; perpetrator.Sex = sex != null ? (SexEnum)Enum.Parse(typeof(SexEnum), sex, true) : SexEnum.Unknown; perpetrators.Add(perpetrator); } return(perpetrators); }
private PerpetratorData Modify(PerpetratorData perpetratorData, JToken json) { var data = perpetratorData ?? new PerpetratorData(); data.Name = json["name"] != null?json.Value <string>("name") : data.Name; var sexString = json["sex"] != null?json.Value <string>("sex") : null; data.Sex = sexString != null ? (SexEnum)Enum.Parse(typeof(SexEnum), sexString, true) : SexEnum.Unknown; var skinColorString = json["skinColor"] != null?json.Value <string>("skinColor") : null; data.SkinColor = skinColorString != null ? (SkinColorEnum)Enum.Parse(typeof(SkinColorEnum), skinColorString, true) : SkinColorEnum.Unknown; data.Clothing = json["clothing"] != null?json.Value <string>("clothing") : data.Clothing; data.MinimumAge = json["minimumAge"] != null?json.Value <int>("minimumAge") : data.MinimumAge; data.MaximumAge = json["maximumAge"] != null?json.Value <int>("maximumAge") : data.MaximumAge; data.UniqueProperties = json["uniqueProperties"] != null?json.Value <string>("uniqueProperties") : data.UniqueProperties; return(data); }
private PerpetratorData Modify(PerpetratorData perpetratorData, JToken json) { var data = perpetratorData ?? new PerpetratorData(); data.Name = json["name"] != null ? json.Value<string>("name") : data.Name; var sexString = json["sex"] != null ? json.Value<string>("sex") : null; data.Sex = sexString != null ? (SexEnum) Enum.Parse(typeof(SexEnum), sexString, true) : SexEnum.Unknown; var skinColorString = json["skinColor"] != null ? json.Value<string>("skinColor") : null; data.SkinColor = skinColorString != null ? (SkinColorEnum)Enum.Parse(typeof(SkinColorEnum), skinColorString, true) : SkinColorEnum.Unknown; data.Clothing = json["clothing"] != null ? json.Value<string>("clothing") : data.Clothing; data.MinimumAge = json["minimumAge"] != null ? json.Value<int>("minimumAge") : data.MinimumAge; data.MaximumAge = json["maximumAge"] != null ? json.Value<int>("maximumAge") : data.MaximumAge; data.UniqueProperties = json["uniqueProperties"] != null ? json.Value<string>("uniqueProperties") : data.UniqueProperties; return data; }