58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Catamaran
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Расширение для класса DrawingBoat
|
|||
|
/// </summary>
|
|||
|
internal static class ExtentionBoat
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Разделитель для записи информации по объекту в файл
|
|||
|
/// </summary>
|
|||
|
private static readonly char _separatorForObject = ':';
|
|||
|
/// <summary>
|
|||
|
/// Создание объекта из строки
|
|||
|
/// </summary>
|
|||
|
/// <param name="info"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static DrawingBoat CreateDrawingBoat(this string info)
|
|||
|
{
|
|||
|
string[] strs = info.Split(_separatorForObject);
|
|||
|
if (strs.Length == 3)
|
|||
|
{
|
|||
|
return new DrawingBoat(Convert.ToInt32(strs[0]),
|
|||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
|||
|
}
|
|||
|
if (strs.Length == 6)
|
|||
|
{
|
|||
|
return new DrawingCatamaran(Convert.ToInt32(strs[0]),
|
|||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
|||
|
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
|
|||
|
Convert.ToBoolean(strs[5]));
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Получение данных для сохранения в файл
|
|||
|
/// </summary>
|
|||
|
/// <param name="DrawingBoat"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static string GetDataForSave(this DrawingBoat DrawingBoat)
|
|||
|
{
|
|||
|
var Boat = DrawingBoat.Catamaran;
|
|||
|
var str = $"{Boat.Speed}{_separatorForObject}{Boat.Weight}{_separatorForObject}{Boat.BodyColor.Name}";
|
|||
|
if (!(Boat is EntityCatamaran Catamaran))
|
|||
|
{
|
|||
|
return str;
|
|||
|
}
|
|||
|
return $"{str}{_separatorForObject}{Catamaran.DopColor.Name}{_separatorForObject}{Catamaran.Floats}{_separatorForObject}{Catamaran.Sail}";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|