55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|