From 0b68380b1e24fc4354ea079ea80012cf7ef073a7 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Sun, 14 Apr 2024 11:51:59 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B2=20?= =?UTF-8?q?Entities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/EntityAirplane.cs | 22 +++++++++++++++++ .../Entities/EntityAirplaneWithRadar.cs | 24 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs index 3e6fe12..e2732d9 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs @@ -46,5 +46,27 @@ { BodyColor = bodyColor; } + + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityAirplane), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityAirplane? CreateEntityAirplane(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityAirplane)) + return null; + + return new EntityAirplane(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } } } \ No newline at end of file diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplaneWithRadar.cs index f73d974..03085e9 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplaneWithRadar.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplaneWithRadar.cs @@ -44,5 +44,29 @@ { AdditionalColor = additionalColor; } + + /// + /// Переопределение метода создания объекта из массива строк + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityAirplaneWithRadar), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Wheels.ToString(), Radar.ToString() }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityAirplaneWithRadar? CreateEntityAirplaneWithRadar(string[] strs) + { + if (strs.Length != 7 || strs[0] != nameof(EntityAirplaneWithRadar)) + return null; + + return new EntityAirplaneWithRadar(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), + Color.FromName(strs[3]), Color.FromName(strs[4]), + Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6])); + } } }