PIBD-11_Basalov_A.D_Simple/ProjectElectricLocomotive/Drawnings/ExtensionDrawningLocomotive.cs
2024-04-25 16:03:43 +03:00

55 lines
2.0 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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectElectricLocomotive.Entities;
namespace ProjectElectricLocomotive.Drawnings
{
public static class ExtensionDrawningLocomotive
{
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separatorForObject = ":";
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info">Строка с данными для создания объекта</param>
/// <returns>Объект</returns>
public static DrawningLocomotive? CreateDrawningLocomotive(this string info)
{
string[] strs = info.Split(_separatorForObject);
EntityLocomotive? locomotive = EntityElectricLocomotive.CreateEntityElectricLocomotive(strs);
if (locomotive != null)
{
return new DrawningElectricLocomotive((EntityElectricLocomotive)locomotive);
}
locomotive = EntityLocomotive.CreateEntityLocomotive(strs);
if (locomotive != null)
{
return new DrawningLocomotive(locomotive);
}
return null;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawningLocomotive">Сохраняемый объект</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawningLocomotive drawningLocomotive)
{
string[]? array = drawningLocomotive?.EntityLocomotive?.GetStringRepresentation();
if (array == null)
{
return string.Empty;
}
return string.Join(_separatorForObject, array);
}
}
}