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])); + } } }