From 4ee8cd8d83cac66f316217b90488afa4ac26d7d2 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Sun, 12 Dec 2021 16:38:08 +0300 Subject: [PATCH] fixes for the previous commit --- DTLib.csproj | 3 ++- Dtsod/DtsodV22.cs | 2 +- Extensions/IfMethod.cs | 24 +++++++++++++++++++ ...oStringConverter.cs => StringConverter.cs} | 2 +- Network/FSP.cs | 4 ++-- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 Extensions/IfMethod.cs rename Extensions/{ToStringConverter.cs => StringConverter.cs} (99%) diff --git a/DTLib.csproj b/DTLib.csproj index 1fde41c..75c594f 100644 --- a/DTLib.csproj +++ b/DTLib.csproj @@ -36,7 +36,8 @@ - + + diff --git a/Dtsod/DtsodV22.cs b/Dtsod/DtsodV22.cs index 0755976..1e55848 100644 --- a/Dtsod/DtsodV22.cs +++ b/Dtsod/DtsodV22.cs @@ -400,7 +400,7 @@ namespace DTLib.Dtsod switch (value.Type) { case ValueTypes.List: - outBuilder.Append('[').Append(ToStringConverter.MergeToString((IEnumerable)value.Value, ",")).Append(']'); + outBuilder.Append('[').Append(StringConverter.MergeToString((IEnumerable)value.Value, ",")).Append(']'); //outBuilder.Append("\"list deconstruction is'nt implemented yet\""); break; case ValueTypes.Complex: diff --git a/Extensions/IfMethod.cs b/Extensions/IfMethod.cs new file mode 100644 index 0000000..92a670d --- /dev/null +++ b/Extensions/IfMethod.cs @@ -0,0 +1,24 @@ +using System; + +namespace DTLib.Extensions +{ + public static class IfMethod + { + public static T If(this T input, bool condition, Func if_true, Func if_false) => + condition ? if_true(input) : if_false(input); + + public static void If(this T input, bool condition, Action if_true, Action if_false) + { + if (condition) if_true(input); + else if_false(input); + } + + public static T If(this T input, bool condition, Func if_true) => + condition ? if_true(input) : input; + + public static void If(this T input, bool condition, Action if_true) + { + if (condition) if_true(input); + } + } +} diff --git a/Extensions/ToStringConverter.cs b/Extensions/StringConverter.cs similarity index 99% rename from Extensions/ToStringConverter.cs rename to Extensions/StringConverter.cs index f6b0f43..7a29e7d 100644 --- a/Extensions/ToStringConverter.cs +++ b/Extensions/StringConverter.cs @@ -3,7 +3,7 @@ using System.Text; namespace DTLib.Extensions { - public static class ToStringConverter + public static class StringConverter { public static Encoding UTF8 = new UTF8Encoding(false); public static byte[] ToBytes(this string str) => UTF8.GetBytes(str); diff --git a/Network/FSP.cs b/Network/FSP.cs index 7884da2..1920458 100644 --- a/Network/FSP.cs +++ b/Network/FSP.cs @@ -70,7 +70,7 @@ namespace DTLib.Network MainSocket.SendPackage("ready".ToBytes()); int packagesCount = 0; byte[] buffer = new byte[5120]; - int fullPackagesCount = FrameworkFix.Truncate(Filesize / buffer.Length); + int fullPackagesCount = (Filesize / buffer.Length).Truncate(); // получение полных пакетов файла for (byte n = 0; packagesCount < fullPackagesCount; packagesCount++) { @@ -114,7 +114,7 @@ namespace DTLib.Network MainSocket.GetAnswer("ready"); byte[] buffer = new byte[5120]; int packagesCount = 0; - int fullPackagesCount = FrameworkFix.Truncate(Filesize / buffer.Length); + int fullPackagesCount = (Filesize / buffer.Length).Truncate(); // отправка полных пакетов файла for (; packagesCount < fullPackagesCount; packagesCount++) {