51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using ProjectAirbus.Entities;
|
|||
|
|
|||
|
namespace ProjectAirbus.Drawnings
|
|||
|
{
|
|||
|
public static class ExtentionDrawningAirbus
|
|||
|
{
|
|||
|
// создание объекта из строки
|
|||
|
public static DrawningAirbus? CreateDrawningAirbus(this string info, char separatorForObject, int width, int height)
|
|||
|
{
|
|||
|
string[] strs = info.Split(separatorForObject);
|
|||
|
if (strs.Length == 3)
|
|||
|
{
|
|||
|
return new DrawningAirbus(
|
|||
|
Convert.ToInt32(strs[0]),
|
|||
|
Convert.ToInt32(strs[1]),
|
|||
|
Color.FromName(strs[2]), width, height);
|
|||
|
}
|
|||
|
if (strs.Length == 6)
|
|||
|
{
|
|||
|
return new DrawningPlane(
|
|||
|
Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]),
|
|||
|
Color.FromName(strs[2]), Color.FromName(strs[3]),
|
|||
|
Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]),
|
|||
|
width, height);
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
// Получение данных для сохранения в файл
|
|||
|
public static string GetDataForSave(this DrawningAirbus drawningAirbus, char separatorForObject)
|
|||
|
{
|
|||
|
var airbus = drawningAirbus.EntityAirbus;
|
|||
|
if (airbus == null)
|
|||
|
{
|
|||
|
return string.Empty;
|
|||
|
}
|
|||
|
var str = $"{airbus.Speed}{separatorForObject}{airbus.Weight}{separatorForObject}{airbus.BodyColor.Name}";
|
|||
|
if (airbus is not EntityPlane plane)
|
|||
|
{
|
|||
|
return str;
|
|||
|
}
|
|||
|
return $"{str}{separatorForObject}{plane.AdditionalColor.Name}{separatorForObject}{plane.IsCompartment}{separatorForObject}{plane.IsAdditionalEngine}";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|