using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormtrooper.CollectionGenericObjects;
///
/// Класс, хранящий информацию по коллекции
///
public class CollectionInfo : IEquatable
{
///
/// Название
///
public string Name { get; private set; }
///
/// Тип
///
public CollectionType CollectionType { get; private set; }
///
/// Описание
///
public string Description { get; private set; }
///
/// Разделитель для записи информации по объекту в файл
///
private static readonly string _separator = "-";
///
/// Конструктор
///
///
///
///
public CollectionInfo(string name, CollectionType collectionType, string description)
{
Name = name;
CollectionType = collectionType;
Description = description;
}
///
/// Создание объекта из строки
///
///
///
public static CollectionInfo? GetCollectionInfo(string data)
{
string[] strs = data.Split(_separator,
StringSplitOptions.RemoveEmptyEntries);
if (strs.Length < 1 || strs.Length > 3)
{
return null;
}
return new CollectionInfo(strs[0],
(CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ?
strs[2] : string.Empty);
}
public override string ToString()
{
return Name + _separator + CollectionType + _separator + Description;
}
public bool Equals(CollectionInfo? other)
{
return Name == other?.Name;
}
public override bool Equals(object? obj)
{
return Equals(obj as CollectionInfo);
}
public override int GetHashCode()
{
return Name.GetHashCode();
}
}