diff --git a/anbs_cp/Classes/NewtonsoftJsonSerializer.cs b/anbs_cp/Classes/NewtonsoftJsonSerializer.cs
new file mode 100644
index 0000000..b6da70d
--- /dev/null
+++ b/anbs_cp/Classes/NewtonsoftJsonSerializer.cs
@@ -0,0 +1,15 @@
+using anbs_cp.Interfaces;
+
+using Newtonsoft.Json;
+
+namespace anbs_cp.Classes;
+
+///
+public class NewtonsoftJsonSerializer: ISerializer
+{
+ ///
+ public string Serialize (T data) => JsonConvert.SerializeObject(data);
+
+ ///
+ public T? Deserialize (string json) => JsonConvert.DeserializeObject(json);
+}
\ No newline at end of file
diff --git a/anbs_cp/Classes/SysTextSerializer.cs b/anbs_cp/Classes/SysTextSerializer.cs
new file mode 100644
index 0000000..9ec096e
--- /dev/null
+++ b/anbs_cp/Classes/SysTextSerializer.cs
@@ -0,0 +1,15 @@
+using System.Text.Json;
+
+using anbs_cp.Interfaces;
+
+namespace anbs_cp.Classes;
+
+///
+public class SysTextSerializer: ISerializer
+{
+ ///
+ public string Serialize (T data) => JsonSerializer.Serialize(data);
+
+ ///
+ public T? Deserialize (string json) => JsonSerializer.Deserialize(json);
+}
\ No newline at end of file
diff --git a/anbs_cp/Classes/TypeConverter.cs b/anbs_cp/Classes/TypeConverter.cs
index 60e768b..687b6fc 100644
--- a/anbs_cp/Classes/TypeConverter.cs
+++ b/anbs_cp/Classes/TypeConverter.cs
@@ -71,7 +71,7 @@ public static class TypeConverter
/// Тип
/// Значение типа
/// Значение в
- public static string TypeToStr (T value) => Serializer.Serialize(value);
+ public static string TypeToStr (T value) => new SysTextSerializer().Serialize(value);
#endregion
@@ -157,7 +157,7 @@ public static class TypeConverter
/// Значение по умолчанию
/// Значение в
public static T StrToType(string value, T defaultValue) =>
- Serializer.Deserialize(value) ?? defaultValue;
+ new SysTextSerializer().Deserialize(value) ?? defaultValue;
#endregion
}
\ No newline at end of file
diff --git a/anbs_cp/Classes/Serializer.cs b/anbs_cp/Interfaces/ISerializer.cs
similarity index 67%
rename from anbs_cp/Classes/Serializer.cs
rename to anbs_cp/Interfaces/ISerializer.cs
index e8eafeb..23e71ec 100644
--- a/anbs_cp/Classes/Serializer.cs
+++ b/anbs_cp/Interfaces/ISerializer.cs
@@ -1,11 +1,9 @@
-using System.Text.Json;
-
-namespace anbs_cp.Classes;
+namespace anbs_cp.Interfaces;
///
-/// Класс для сериализации моделей
+/// Сериализация моделей, классов и других объектов
///
-public static class Serializer
+public interface ISerializer
{
///
/// Сериализация данных в строку.
@@ -13,7 +11,7 @@ public static class Serializer
/// Тип данных
/// Данные
/// Сериализованные данные
- public static string Serialize(T data) => JsonSerializer.Serialize(data);
+ string Serialize (T data);
///
/// Десериализация данных из json-строки
@@ -21,5 +19,5 @@ public static class Serializer
/// Ожидаемый тип данных
/// Сериализованные данные
/// Данные
- public static T? Deserialize(string json) => JsonSerializer.Deserialize(json);
+ T? Deserialize (string json);
}
\ No newline at end of file
diff --git a/anbs_cp/Structs/TwoDimSize.cs b/anbs_cp/Structs/TwoDimSize.cs
index 95b1415..c46a4c7 100644
--- a/anbs_cp/Structs/TwoDimSize.cs
+++ b/anbs_cp/Structs/TwoDimSize.cs
@@ -86,7 +86,7 @@ public struct TwoDimSize (int width = 0, int height = 0): ISerializable
/// Сериализовать элемент в формат json
///
/// Строка в формате json
- public readonly string Serialize () => Serializer.Serialize(ToString());
+ public readonly string Serialize () => new SysTextSerializer().Serialize(ToString());
///
/// Восстановить элемент из формата json
@@ -95,7 +95,7 @@ public struct TwoDimSize (int width = 0, int height = 0): ISerializable
public void Deserialize (string json)
{
// Десериализую строку
- string deserialized = Serializer.Deserialize(json) ?? "0:0";
+ string deserialized = new SysTextSerializer().Deserialize(json) ?? "0:0";
// Перевожу строку в двумерный размер
TwoDimSize result = Parse(deserialized);
diff --git a/anbs_cp/anbs_cp.csproj b/anbs_cp/anbs_cp.csproj
index 08ec26e..da024f9 100644
--- a/anbs_cp/anbs_cp.csproj
+++ b/anbs_cp/anbs_cp.csproj
@@ -2,7 +2,7 @@
net8.0
- 2023.1217.0
+ 2024.1.1
Александр Бабаев
Набор компонентов ANB Software
Библиотека полезных методов языка C#
@@ -41,6 +41,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/anbsoftware.componentspack.sln.DotSettings b/anbsoftware.componentspack.sln.DotSettings
index 04c25e0..9d923c8 100644
--- a/anbsoftware.componentspack.sln.DotSettings
+++ b/anbsoftware.componentspack.sln.DotSettings
@@ -7,13 +7,16 @@
True
True
True
+ True
True
True
True
True
True
+ True
True
True
+ True
True
True
True
@@ -29,6 +32,7 @@
True
True
True
+ True
True
True
True
diff --git a/demo/OsInfoFrm.cs b/demo/OsInfoFrm.cs
index 4c0e8b8..5ef8140 100644
--- a/demo/OsInfoFrm.cs
+++ b/demo/OsInfoFrm.cs
@@ -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);
}
}
diff --git a/demo/SampleMapperTest.cs b/demo/SampleMapperTest.cs
index 2386164..9a01edf 100644
--- a/demo/SampleMapperTest.cs
+++ b/demo/SampleMapperTest.cs
@@ -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 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}";