20240101
This commit is contained in:
parent
ce063558c5
commit
f4872e1d49
15
anbs_cp/Classes/NewtonsoftJsonSerializer.cs
Normal file
15
anbs_cp/Classes/NewtonsoftJsonSerializer.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using anbs_cp.Interfaces;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace anbs_cp.Classes;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class NewtonsoftJsonSerializer: ISerializer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string Serialize<T> (T data) => JsonConvert.SerializeObject(data);
|
||||
|
||||
/// <inheritdoc />
|
||||
public T? Deserialize<T> (string json) => JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
15
anbs_cp/Classes/SysTextSerializer.cs
Normal file
15
anbs_cp/Classes/SysTextSerializer.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Text.Json;
|
||||
|
||||
using anbs_cp.Interfaces;
|
||||
|
||||
namespace anbs_cp.Classes;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class SysTextSerializer: ISerializer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string Serialize<T> (T data) => JsonSerializer.Serialize(data);
|
||||
|
||||
/// <inheritdoc />
|
||||
public T? Deserialize<T> (string json) => JsonSerializer.Deserialize<T>(json);
|
||||
}
|
@ -71,7 +71,7 @@ public static class TypeConverter
|
||||
/// <typeparam name="T">Тип</typeparam>
|
||||
/// <param name="value">Значение типа</param>
|
||||
/// <returns>Значение в <see cref="string"/></returns>
|
||||
public static string TypeToStr<T> (T value) => Serializer.Serialize(value);
|
||||
public static string TypeToStr<T> (T value) => new SysTextSerializer().Serialize(value);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -157,7 +157,7 @@ public static class TypeConverter
|
||||
/// <param name="defaultValue">Значение по умолчанию</param>
|
||||
/// <returns>Значение в <see cref="T"/></returns>
|
||||
public static T StrToType<T>(string value, T defaultValue) =>
|
||||
Serializer.Deserialize<T>(value) ?? defaultValue;
|
||||
new SysTextSerializer().Deserialize<T>(value) ?? defaultValue;
|
||||
|
||||
#endregion
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace anbs_cp.Classes;
|
||||
namespace anbs_cp.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// Класс для сериализации моделей
|
||||
/// Сериализация моделей, классов и других объектов
|
||||
/// </summary>
|
||||
public static class Serializer
|
||||
public interface ISerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Сериализация данных <paramref name="data"/> в строку.
|
||||
@ -13,7 +11,7 @@ public static class Serializer
|
||||
/// <typeparam name="T">Тип данных</typeparam>
|
||||
/// <param name="data">Данные</param>
|
||||
/// <returns>Сериализованные данные</returns>
|
||||
public static string Serialize<T>(T data) => JsonSerializer.Serialize(data);
|
||||
string Serialize<T> (T data);
|
||||
|
||||
/// <summary>
|
||||
/// Десериализация данных из json-строки <paramref name="json"/>
|
||||
@ -21,5 +19,5 @@ public static class Serializer
|
||||
/// <typeparam name="T">Ожидаемый тип данных</typeparam>
|
||||
/// <param name="json">Сериализованные данные</param>
|
||||
/// <returns>Данные</returns>
|
||||
public static T? Deserialize<T>(string json) => JsonSerializer.Deserialize<T>(json);
|
||||
T? Deserialize<T> (string json);
|
||||
}
|
@ -86,7 +86,7 @@ public struct TwoDimSize (int width = 0, int height = 0): ISerializable
|
||||
/// Сериализовать элемент в формат json
|
||||
/// </summary>
|
||||
/// <returns>Строка в формате json</returns>
|
||||
public readonly string Serialize () => Serializer.Serialize(ToString());
|
||||
public readonly string Serialize () => new SysTextSerializer().Serialize(ToString());
|
||||
|
||||
/// <summary>
|
||||
/// Восстановить элемент из формата json
|
||||
@ -95,7 +95,7 @@ public struct TwoDimSize (int width = 0, int height = 0): ISerializable
|
||||
public void Deserialize (string json)
|
||||
{
|
||||
// Десериализую строку
|
||||
string deserialized = Serializer.Deserialize<string>(json) ?? "0:0";
|
||||
string deserialized = new SysTextSerializer().Deserialize<string>(json) ?? "0:0";
|
||||
|
||||
// Перевожу строку в двумерный размер
|
||||
TwoDimSize result = Parse(deserialized);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Version>2023.1217.0</Version>
|
||||
<Version>2024.1.1</Version>
|
||||
<Authors>Александр Бабаев</Authors>
|
||||
<Product>Набор компонентов ANB Software</Product>
|
||||
<Description>Библиотека полезных методов языка C#</Description>
|
||||
@ -41,6 +41,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -7,13 +7,16 @@
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=abcdefghijkmnopqrstuvwxyz/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ABCDEFGHJKLMNOPQRSTUVWXYZ/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=anbs/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=C_0435_0440_0438_0430_043B_0438_0437_0430_0446_0438_044F/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Darkseal/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Encryptor/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Glendower/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0412_0435_0440_043D_0451_043C/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0412_0438_0434_0435_043E_043A_0430_0440_0442_0430/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0414_0435_0441_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_043D_043D_044B_0439/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0414_0435_0441_0435_0440_0438_0430_043B_0438_0437_0443_044E/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_041F_0430_0440_0441_0435_0440/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0421_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_043D_043D_0430_044F/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0421_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_043D_043D_044B_0435/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0421_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_0442_044C/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0421_043E_0437_0434_0430_0451_043C/@EntryIndexedValue">True</s:Boolean>
|
||||
@ -29,6 +32,7 @@
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_043F_0443_0442_0451_043C/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0435_0440_0438_0430_043B_0438_0437_0430_0446_0438_0438/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0435_0440_0438_0430_043B_0438_0437_0430_0446_0438_044F/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_043D_043D_043E_0433_043E/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0447_0451_0442/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0447_0451_0442_0447_0438_043A/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0445_044D_0448_0430/@EntryIndexedValue">True</s:Boolean>
|
||||
|
@ -12,16 +12,16 @@ public sealed partial class OsInfoFrm: Form
|
||||
private void OsInfoFrm_Load (object sender, EventArgs e)
|
||||
{
|
||||
textBox.Text = @"Процессор(ы) | ";
|
||||
textBox.Text += Serializer.Serialize(OsInfo.Processors);
|
||||
textBox.Text += new SysTextSerializer().Serialize(OsInfo.Processors);
|
||||
textBox.Text += @"Оперативная память | ";
|
||||
textBox.Text += Serializer.Serialize(OsInfo.RAM);
|
||||
textBox.Text += new SysTextSerializer().Serialize(OsInfo.RAM);
|
||||
textBox.Text += @"Видеокарта | ";
|
||||
textBox.Text += Serializer.Serialize(OsInfo.Videos);
|
||||
textBox.Text += new SysTextSerializer().Serialize(OsInfo.Videos);
|
||||
textBox.Text += @"Диски | ";
|
||||
textBox.Text += Serializer.Serialize(OsInfo.Drives);
|
||||
textBox.Text += new SysTextSerializer().Serialize(OsInfo.Drives);
|
||||
textBox.Text += @"Windows | ";
|
||||
textBox.Text += Serializer.Serialize(OsInfo.Windows);
|
||||
textBox.Text += new SysTextSerializer().Serialize(OsInfo.Windows);
|
||||
textBox.Text += @"Net | ";
|
||||
textBox.Text += Serializer.Serialize(OsInfo.Net);
|
||||
textBox.Text += new SysTextSerializer().Serialize(OsInfo.Net);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public sealed partial class SampleMapperTest: Form
|
||||
DemoDateTime = default
|
||||
};
|
||||
|
||||
string serialize1 = Serializer.Serialize(demo2);
|
||||
string serialize1 = new SysTextSerializer().Serialize(demo2);
|
||||
|
||||
SimpleMapper.MapMode mode = MapModeEdit.SelectedIndex switch
|
||||
{
|
||||
@ -38,7 +38,7 @@ public sealed partial class SampleMapperTest: Form
|
||||
|
||||
SimpleMapper.MapEx(demo1, ref demo2, mode, new List<string>());
|
||||
|
||||
string serialize2 = Serializer.Serialize(demo2);
|
||||
string serialize2 = new SysTextSerializer().Serialize(demo2);
|
||||
|
||||
// ReSharper disable once LocalizableElement
|
||||
ResultArea.Text = $"Класс Demo2 до связывания:\r\n{serialize1}\r\nи после:\r\n{serialize2}";
|
||||
|
Loading…
x
Reference in New Issue
Block a user