TranslationPair: Reuse code + fix potential null exception

This commit is contained in:
Ivandro Jao 2023-02-24 22:34:25 +00:00
parent 33f05cd1f8
commit 1f26fab54d

View File

@ -1,16 +1,13 @@
using System;
using Nikse.SubtitleEdit.Core.Common;
namespace Nikse.SubtitleEdit.Core.Translate
{
public class TranslationPair : IEquatable<TranslationPair>
{
public string Name { get; set; }
public string Code { get; set; }
public TranslationPair()
{
}
public string Name { get; }
public string Code { get; }
public TranslationPair(string name, string code)
{
@ -18,29 +15,10 @@ namespace Nikse.SubtitleEdit.Core.Translate
Code = code;
}
public override string ToString()
{
return UpcaseFirstLetter(Name);
}
public override string ToString() => Name.CapitalizeFirstLetter();
private static string UpcaseFirstLetter(string text)
{
if (text.Length > 1)
{
text = char.ToUpper(text[0]) + text.Substring(1).ToLowerInvariant();
}
public bool Equals(TranslationPair other) => other != null && Code.Equals(other.Code);
return text;
}
public bool Equals(TranslationPair other)
{
return Code.Equals(other.Code);
}
public override int GetHashCode()
{
return Code != null ? Code.GetHashCode() : 0;
}
public override int GetHashCode() => Code != null ? Code.GetHashCode() : 0;
}
}