PIBD-14_Khalikova.A.R_Storm.../ProjectStormtrooper/Drawnings/ExtentionDrawningStormtrooper.cs

54 lines
2.1 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 ProjectStormtrooper.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormtrooper.Drawnings
{
public static class ExtentionDrawningStormtrooper
{
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separatorForObject = ":";
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info">Строка с данными для создания объекта</param>
/// <returns>Объект</returns>
public static DrawningStormtrooperBase? CreateDrawningStormtrooper(this string info)
{
string[] strs = info.Split(_separatorForObject);
EntityStormtrooperBase? stormtrooper = EntityStormtrooper.CreateEntityStormtrooper(strs);
if (stormtrooper != null)
{
return new DrawingStormtrooper((EntityStormtrooper)stormtrooper);
}
stormtrooper = EntityStormtrooperBase.CreateEntityBaseStormtrooper(strs);
if (stormtrooper != null)
{
return new DrawningStormtrooperBase(stormtrooper);
}
return null;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawningStormtrooper">Сохраняемый объект</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawningStormtrooperBase drawningBaseStormtrooper)
{
string[]? array = drawningBaseStormtrooper?.EntityStormtrooperBase?.GetStringRepresentation();
if (array == null)
{
return string.Empty;
}
return string.Join(_separatorForObject, array);
}
}
}