PIBD-14_Lavrova_K.I._Simple/solution/lab1/Drawnings/ExtentionDrawningTrackedVehicle.cs

53 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using lab1.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lab1.Drawnings;
public static class ExtentionDrawningTrackedVehicle
{
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separatorForObject = ":";
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info">Строка с данными для создания объекта</param>
/// <returns>Объект</returns>
public static DrawningTrackedVehicle? CreateDrawningTrackedVehicle(this string info)
{
string[] strs = info.Split(_separatorForObject);
EntityTrackedVehicle? fighter = EntityFighter.CreateEntityStormtrooper(strs);
if (fighter != null)
{
return new DrawningEntityFighter((EntityFighter)fighter);
}
fighter = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs);
if (fighter != null)
{
return new DrawningTrackedVehicle(fighter);
}
return null;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawningStormtrooper">Сохраняемый объект</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawningTrackedVehicle drawningBaseStormtrooper)
{
string[]? array = drawningBaseStormtrooper?.EntityTrackedVehicle?.GetStringRepresentation();
if (array == null)
{
return string.Empty;
}
return string.Join(_separatorForObject, array);
}
}