64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
namespace ProjectCruiser.CollectionGenericObj;
|
|
|
|
// Класс, хранящиий информацию по коллекции
|
|
/// </summary>
|
|
public class CollectionInfo : IEquatable<CollectionInfo>
|
|
{
|
|
// Название коллекции
|
|
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)
|
|
{
|
|
// if (Name != other.Name) return false; >>>
|
|
// else if (CollectionType != other.CollectionType) return false;
|
|
// else if (Description != other.Description) return false;
|
|
|
|
return Name == other?.Name;
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
return Equals(obj as CollectionInfo);
|
|
}
|
|
public override int GetHashCode()
|
|
{
|
|
return Name.GetHashCode();
|
|
}
|
|
}
|
|
|