Radarr/src/NzbDrone.Core/CustomFormats/CustomFormat.cs

69 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.CustomFormats
{
public class CustomFormat : ModelBase, IEquatable<CustomFormat>
{
public CustomFormat()
{
}
public CustomFormat(string name, params string[] tags)
{
Name = name;
FormatTags = tags.Select(t => new FormatTag(t)).ToList();
}
public string Name { get; set; }
public List<FormatTag> FormatTags { get; set; }
public override string ToString()
{
return Name;
}
public static CustomFormat None => new CustomFormat("None");
public bool Equals(CustomFormat other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return int.Equals(Id, other.Id);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((CustomFormat) obj);
}
public override int GetHashCode()
{
return (Id != null ? Id.GetHashCode() : 0);
}
}
public static class CustomFormatExtensions
{
public static string ToExtendedString(this IEnumerable<CustomFormat> formats)
{
return string.Join(", ", formats.Select(f => f.ToString()));
}
public static List<CustomFormat> WithNone(this IEnumerable<CustomFormat> formats)
{
var list = formats.ToList();
if (list.Any()) return list;
return new List<CustomFormat>{CustomFormat.None};
}
}
}