mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
TranslationPair: Reuse code + fix potential null exception
This commit is contained in:
parent
33f05cd1f8
commit
1f26fab54d
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user