From db78391b7f9cc2d81457b0ee846c7d9313c1b8ea Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 26 Nov 2023 23:07:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20ExtentionLocomo?= =?UTF-8?q?tive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/ExtentionLocomotive.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs diff --git a/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs new file mode 100644 index 0000000..aed65f9 --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectElectricLocomotive.Entities; + +namespace ProjectElectricLocomotive.DrawingObjects +{ + public static class ExtentionLocomotive + { + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Разделитель даннных + /// Ширина + /// Высота + /// Объект + public static DrawingLocomotive? CreateDrawningCar(this string info, char + separatorForObject, int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawingLocomotive(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); + } + if (strs.Length == 7) + { + return new DrawningSportCar(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]), + Color.FromName(strs[3]), + Convert.ToBoolean(strs[4]), + Convert.ToBoolean(strs[5]), + Convert.ToBoolean(strs[6]), width, height); + } + return null; + } + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Разделитель даннных + /// Строка с данными по объекту + public static string GetDataForSave(this DrawingLocomotive drawningCar, + char separatorForObject) + { + var loco = drawningCar.EntityLocomotive; + if (loco == null) + { + return string.Empty; + } + var str = + $"{loco.Speed}{separatorForObject}{loco.Weight}{separatorForObject}{loco.BodyColor.Name}"; + if (loco is not EntityElectricLocomotive electricLocomotive) + { + return str; + } + return + $"{str}{separatorForObject}{electricLocomotive.AdditionalColor.Name}{separatorForObject}{electricLocomotive.Pantograph}{separatorForObject}{electricLocomotive.Compartment}"; + } + + } +}