| 19 | } |
| 20 | |
| 21 | partial class LocalizedString : IEquatable<LocalizedString>, IEquatable<string>, IComparable, IComparable<LocalizedString>, IComparable<string> |
| 22 | { |
| 23 | /// <summary> |
| 24 | /// Empty string without localization. |
| 25 | /// </summary> |
| 26 | public static readonly LocalizedString Empty = new LocalizedString(null); |
| 27 | |
| 28 | /// <summary> |
| 29 | /// Initializes a new instance of the <see cref="LocalizedString"/> class. |
| 30 | /// </summary> |
| 31 | /// <param name="value">The value.</param> |
| 32 | public LocalizedString(string value) |
| 33 | { |
| 34 | Value = value; |
| 35 | } |
| 36 | |
| 37 | /// <summary> |
| 38 | /// Gets the localized plural string for the current language by using string id lookup. |
| 39 | /// </summary> |
| 40 | /// <param name="n">The value count for plural message selection.</param> |
| 41 | /// <returns>The localized text.</returns> |
| 42 | public string ToStringPlural(int n) |
| 43 | { |
| 44 | return string.IsNullOrEmpty(Value) ? Localization.GetPluralString(Id, n) : string.Format(Value, n); |
| 45 | } |
| 46 | |
| 47 | /// <summary> |
| 48 | /// Implicit converter of <see cref="LocalizedString"/> into <see cref="string"/>. |
| 49 | /// </summary> |
| 50 | /// <param name="str">The localized string.</param> |
| 51 | /// <returns>The string.</returns> |
| 52 | public static implicit operator string(LocalizedString str) |
| 53 | { |
| 54 | if ((object)str == null) |
| 55 | return null; |
| 56 | return string.IsNullOrEmpty(str.Value) ? Localization.GetString(str.Id) : str.Value; |
| 57 | } |
| 58 | |
| 59 | /// <summary> |
| 60 | /// Implicit converter of <see cref="string"/> into <see cref="LocalizedString"/>. |
| 61 | /// </summary> |
| 62 | /// <param name="str">The string.</param> |
| 63 | /// <returns>The localized string.</returns> |
| 64 | public static implicit operator LocalizedString(string str) |
| 65 | { |
| 66 | if (str == null) |
| 67 | return null; |
| 68 | return new LocalizedString(str); |
| 69 | } |
| 70 | |
| 71 | /// <summary> |
| 72 | /// Compares two localized strings. |
| 73 | /// </summary> |
| 74 | /// <param name="left">The lft string.</param> |
| 75 | /// <param name="right">The right string.</param> |
| 76 | /// <returns>True if both values are equal, otherwise false.</returns> |
| 77 | public static bool operator ==(LocalizedString left, LocalizedString right) |
| 78 | { |
no test coverage detected