Отчистка кода
This commit is contained in:
@@ -1,18 +1,12 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pf2eModel.Model.Common.I18n;
|
||||
|
||||
public class LocaleString : ICollection<LocaleItem>
|
||||
{
|
||||
private readonly List<LocaleItem> _items = [];
|
||||
|
||||
private void AssureDefault()
|
||||
{
|
||||
if (_items.Count == 0)
|
||||
@@ -34,16 +28,19 @@ public class LocaleString : ICollection<LocaleItem>
|
||||
|
||||
private LocaleType _E(string localeString) => LocaleExtension.GetTypeByString(localeString);
|
||||
|
||||
private LocaleType RealLocale(LocaleType locale) => Contains(locale) ? locale : LocaleType.English;
|
||||
private LocaleType RealLocale(LocaleType locale) =>
|
||||
Contains(locale) ? locale : LocaleType.English;
|
||||
|
||||
private LocaleType RealLocale(string localeString) => RealLocale(_E(localeString));
|
||||
|
||||
public LocaleItem GetItem(LocaleType locale) => this.First(c => c.Locale == RealLocale(locale));
|
||||
|
||||
public LocaleItem GetItem(string locale) => this.First(c => c.Locale == RealLocale(locale));
|
||||
|
||||
public string this[LocaleType locale]
|
||||
{
|
||||
get => GetItem(locale).Value;
|
||||
set
|
||||
set
|
||||
{
|
||||
if (Types.Contains(locale))
|
||||
{
|
||||
@@ -65,6 +62,7 @@ public class LocaleString : ICollection<LocaleItem>
|
||||
{
|
||||
this[item.Locale] = item.Value;
|
||||
}
|
||||
|
||||
public void Add(LocaleType locale, string value)
|
||||
{
|
||||
this[locale] = value;
|
||||
@@ -80,10 +78,12 @@ public class LocaleString : ICollection<LocaleItem>
|
||||
{
|
||||
return _items.Contains(item);
|
||||
}
|
||||
|
||||
public bool Contains(LocaleType locale)
|
||||
{
|
||||
return Types.Contains(locale);
|
||||
}
|
||||
|
||||
public bool Contains(string value)
|
||||
{
|
||||
return this.Any(item => item.Value == value);
|
||||
@@ -111,6 +111,7 @@ public class LocaleString : ICollection<LocaleItem>
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
@@ -132,17 +133,17 @@ public class LocaleString : ICollection<LocaleItem>
|
||||
|
||||
return json.ToString();
|
||||
}
|
||||
|
||||
public static LocaleString Deserialize(string input)
|
||||
{
|
||||
JObject json = JObject.Parse(input);
|
||||
LocaleString result = new();
|
||||
|
||||
foreach (var item in json)
|
||||
foreach (KeyValuePair<string, JToken?> item in json)
|
||||
{
|
||||
result[item.Key] = item.ToString();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user