namespace ElectricLocomotive; public static class ExtentionDrawingLocomotiv { public static DrawingLocomotiv? CreateDrawingLoco(this string info, char separatorForObject, int width, int height) { string[] strs = info.Split(separatorForObject); if (strs.Length == 4) { return new DrawingLocomotiv(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), width, height,Color.FromName(strs[2]), Color.FromName(strs[3])); } if (strs.Length == 8) { return new DrawingElectricLocomotiv( Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), width, height, Color.FromName(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]), Color.FromName(strs[5]), Convert.ToBoolean(strs[6]), Convert.ToBoolean(strs[7]) ); } return null; } public static string GetDataForSave(this DrawingLocomotiv drawingLoco, char separatorForObject) { var loco = drawingLoco.EntityLocomotiv; if (loco == null) { return string.Empty; } var str = $"{loco.Speed}{separatorForObject}{loco.Weight}" + $"{separatorForObject}{loco.ColorBody.Name}" + $"{separatorForObject}{loco.ColorWindow.Name}"; if (loco is not EntityElectricLocomotiv electricLocomotiv) { return str; } return $"{str}{separatorForObject}{electricLocomotiv.BatteryColor.Name}{separatorForObject}" + $"{electricLocomotiv.RogaColor.Name}{separatorForObject}" + $"{electricLocomotiv.isBattery}{separatorForObject}{electricLocomotiv.isRoga}"; } }