移除Newtonsoft.Json
This commit is contained in:
parent
facfbbcf73
commit
866be14168
Binary file not shown.
@ -1,2 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 86371939112254644a31e78df202d79c
|
|
||||||
@ -1,20 +1,20 @@
|
|||||||
using Newtonsoft.Json;
|
//using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace StoicGoose.Common.Extensions
|
//namespace StoicGoose.Common.Extensions
|
||||||
{
|
//{
|
||||||
public static class ObjectExtensionMethods
|
// public static class ObjectExtensionMethods
|
||||||
{
|
// {
|
||||||
/* https://dotnetcoretutorials.com/2020/09/09/cloning-objects-in-c-and-net-core/ */
|
// /* https://dotnetcoretutorials.com/2020/09/09/cloning-objects-in-c-and-net-core/ */
|
||||||
public static T Clone<T>(this T source)
|
// public static T Clone<T>(this T source)
|
||||||
{
|
// {
|
||||||
if (source is null) return default;
|
// if (source is null) return default;
|
||||||
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(source, new JsonSerializerSettings()
|
// return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(source, new JsonSerializerSettings()
|
||||||
{
|
// {
|
||||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
// ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||||
}), new JsonSerializerSettings()
|
// }), new JsonSerializerSettings()
|
||||||
{
|
// {
|
||||||
ObjectCreationHandling = ObjectCreationHandling.Replace
|
// ObjectCreationHandling = ObjectCreationHandling.Replace
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,31 +1,31 @@
|
|||||||
using System.IO;
|
//using System.IO;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
//using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace StoicGoose.Common.Extensions
|
//namespace StoicGoose.Common.Extensions
|
||||||
{
|
//{
|
||||||
public static class SerializationExtensionMethods
|
// public static class SerializationExtensionMethods
|
||||||
{
|
// {
|
||||||
public static void SerializeToFile(this object obj, string jsonFileName)
|
// public static void SerializeToFile(this object obj, string jsonFileName)
|
||||||
{
|
// {
|
||||||
SerializeToFile(obj, jsonFileName, new JsonSerializerSettings() { Formatting = Formatting.Indented });
|
// SerializeToFile(obj, jsonFileName, new JsonSerializerSettings() { Formatting = Formatting.Indented });
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static void SerializeToFile(this object obj, string jsonFileName, JsonSerializerSettings serializerSettings)
|
// public static void SerializeToFile(this object obj, string jsonFileName, JsonSerializerSettings serializerSettings)
|
||||||
{
|
// {
|
||||||
using var writer = new StreamWriter(jsonFileName);
|
// using var writer = new StreamWriter(jsonFileName);
|
||||||
writer.Write(JsonConvert.SerializeObject(obj, serializerSettings));
|
// writer.Write(JsonConvert.SerializeObject(obj, serializerSettings));
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static T DeserializeFromFile<T>(this string jsonFileName)
|
// public static T DeserializeFromFile<T>(this string jsonFileName)
|
||||||
{
|
// {
|
||||||
using var reader = new StreamReader(jsonFileName);
|
// using var reader = new StreamReader(jsonFileName);
|
||||||
return (T)JsonConvert.DeserializeObject(reader.ReadToEnd(), typeof(T), new JsonSerializerSettings() { Formatting = Formatting.Indented });
|
// return (T)JsonConvert.DeserializeObject(reader.ReadToEnd(), typeof(T), new JsonSerializerSettings() { Formatting = Formatting.Indented });
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static T DeserializeObject<T>(this string jsonString)
|
// public static T DeserializeObject<T>(this string jsonString)
|
||||||
{
|
// {
|
||||||
return (T)JsonConvert.DeserializeObject(jsonString, typeof(T), new JsonSerializerSettings() { Formatting = Formatting.Indented });
|
// return (T)JsonConvert.DeserializeObject(jsonString, typeof(T), new JsonSerializerSettings() { Formatting = Formatting.Indented });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,37 +1,37 @@
|
|||||||
using System;
|
//using System;
|
||||||
using System.Globalization;
|
//using System.Globalization;
|
||||||
using System.Linq;
|
//using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
//using System.Text.RegularExpressions;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
//using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
//using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace StoicGoose.Common.Localization
|
//namespace StoicGoose.Common.Localization
|
||||||
{
|
//{
|
||||||
public static class Localizer
|
// public static class Localizer
|
||||||
{
|
// {
|
||||||
public static string FallbackCulture { get; set; } = "en";
|
// public static string FallbackCulture { get; set; } = "en";
|
||||||
|
|
||||||
static JObject source = default;
|
// static JObject source = default;
|
||||||
|
|
||||||
public static void Initialize(string jsonData) => source = JsonConvert.DeserializeObject(jsonData) as JObject;
|
// public static void Initialize(string jsonData) => source = JsonConvert.DeserializeObject(jsonData) as JObject;
|
||||||
|
|
||||||
public static CultureInfo[] GetSupportedLanguages() => source?.Children().Select(x => new CultureInfo((x as JProperty).Name)).ToArray() ?? Array.Empty<CultureInfo>();
|
// public static CultureInfo[] GetSupportedLanguages() => source?.Children().Select(x => new CultureInfo((x as JProperty).Name)).ToArray() ?? Array.Empty<CultureInfo>();
|
||||||
|
|
||||||
private static JToken GetToken(string path) => source?.SelectToken($"{CultureInfo.CurrentUICulture.TwoLetterISOLanguageName}.{path}") ?? source?.SelectToken($"{FallbackCulture}.{path}");
|
// private static JToken GetToken(string path) => source?.SelectToken($"{CultureInfo.CurrentUICulture.TwoLetterISOLanguageName}.{path}") ?? source?.SelectToken($"{FallbackCulture}.{path}");
|
||||||
public static string GetString(string path) => GetToken(path)?.Value<string>() ?? path[(path.LastIndexOf('.') + 1)..];
|
// public static string GetString(string path) => GetToken(path)?.Value<string>() ?? path[(path.LastIndexOf('.') + 1)..];
|
||||||
public static string GetString(string path, object parameters)
|
// public static string GetString(string path, object parameters)
|
||||||
{
|
// {
|
||||||
var result = GetString(path);
|
// var result = GetString(path);
|
||||||
var properties = parameters.GetType().GetProperties();
|
// var properties = parameters.GetType().GetProperties();
|
||||||
foreach (Match match in Regex.Matches(result, @"{(?<param>[^}:]*):*(?<format>[^}]*)}").Where(x => x.Success))
|
// foreach (Match match in Regex.Matches(result, @"{(?<param>[^}:]*):*(?<format>[^}]*)}").Where(x => x.Success))
|
||||||
{
|
// {
|
||||||
var property = properties.First(x => x.Name == match.Groups["param"].Value);
|
// var property = properties.First(x => x.Name == match.Groups["param"].Value);
|
||||||
var format = match.Groups["format"].Value;
|
// var format = match.Groups["format"].Value;
|
||||||
var formattedValue = string.IsNullOrEmpty(format) ? $"{property.GetValue(parameters)}" : string.Format($"{{0:{format}}}", property.GetValue(parameters));
|
// var formattedValue = string.IsNullOrEmpty(format) ? $"{property.GetValue(parameters)}" : string.Format($"{{0:{format}}}", property.GetValue(parameters));
|
||||||
result = result.Replace(match.Value, formattedValue);
|
// result = result.Replace(match.Value, formattedValue);
|
||||||
}
|
// }
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using StoicGoose.Common.Extensions;
|
using StoicGoose.Common.Utilities;
|
||||||
using StoicGoose.Common.Utilities;
|
|
||||||
using StoicGoose.Core.Machines;
|
using StoicGoose.Core.Machines;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -571,11 +570,13 @@ static class Program
|
|||||||
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
||||||
|
|
||||||
Configuration configuration;
|
Configuration configuration;
|
||||||
if (!File.Exists(filename) || (configuration = filename.DeserializeFromFile<Configuration>()) == null)
|
//if (!File.Exists(filename) || (configuration = filename.DeserializeFromFile<Configuration>()) == null)
|
||||||
{
|
//{
|
||||||
configuration = new Configuration();
|
// configuration = new Configuration();
|
||||||
configuration.SerializeToFile(filename);
|
// configuration.SerializeToFile(filename);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
configuration = new Configuration();
|
||||||
|
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
@ -588,7 +589,7 @@ static class Program
|
|||||||
|
|
||||||
public static void SaveConfiguration()
|
public static void SaveConfiguration()
|
||||||
{
|
{
|
||||||
Configuration?.SerializeToFile(programConfigPath);
|
//Configuration?.SerializeToFile(programConfigPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetVersionDetails()
|
private static string GetVersionDetails()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user