From 845a719d2904b5b18efc66cdbdcaee7f234d61cf Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Mon, 14 Nov 2022 21:35:24 +0400
Subject: [PATCH] class ExtentionBoat
---
Boats/Boats/ExtentionBoat.cs | 62 ++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
create mode 100644 Boats/Boats/ExtentionBoat.cs
diff --git a/Boats/Boats/ExtentionBoat.cs b/Boats/Boats/ExtentionBoat.cs
new file mode 100644
index 0000000..6fb51bc
--- /dev/null
+++ b/Boats/Boats/ExtentionBoat.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Boats
+{
+ ///
+ /// Расширение для класса DrawingBoat
+ ///
+ internal static class ExtentionBoat
+ {
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly char _separatorForObject = ':';
+ ///
+ /// Создание объекта из строки
+ ///
+ ///
+ ///
+ public static DrawingBoat CreateDraingBoat(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ if (strs.Length == 3)
+ {
+ return new DrawingBoat(
+ Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]),
+ Color.FromName(strs[2])
+ );
+ }
+ if (strs.Length == 6)
+ {
+ return new DrawingCatamaran(
+ Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]),
+ Color.FromName(strs[2]),
+ Color.FromName(strs[3]),
+ Convert.ToBoolean(strs[4]),
+ Convert.ToBoolean(strs[5])
+ );
+ }
+ return null;
+ }
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ ///
+ ///
+ public static string GetDataForSave(this DrawingBoat drawingBoat)
+ {
+ var car = drawingBoat.Boat;
+ var str = $"{car.Speed}{_separatorForObject}{car.Weight}{_separatorForObject}{car.BodyColor.Name}";
+ if (car is not EntityCatamaran catamaran)
+ {
+ return str;
+ }
+ return $"{str}{_separatorForObject}{catamaran.DopColor.Name}{_separatorForObject}{catamaran.Bobbers}{_separatorForObject}{catamaran.Sail}";
+ }
+ }