From 152c42c4bccfb9f9555e1eb533f53572b522fe45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BD=D1=8E=D1=82=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D0=BC=20=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Wed, 20 Nov 2024 01:32:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=BF=D1=80=D0=B5=D0=B4=D1=83=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VkNet.Tests/VkNet.Tests.csproj | 1 + VkNet/Utils/PerformanceActivator.cs | 12 +++++------- VkNet/Utils/Url.cs | 2 ++ VkNet/Utils/Utilities.cs | 2 ++ VkNet/Utils/VkErrorFactory.cs | 7 +++---- VkNet/Utils/VkParameters.cs | 7 +++++-- VkNet/Utils/VkResponse.cs | 2 ++ VkNet/Utils/VkResponseEx.cs | 22 ++++++++++++---------- VkNet/VkApi.cs | 5 ++--- 9 files changed, 34 insertions(+), 26 deletions(-) diff --git a/VkNet.Tests/VkNet.Tests.csproj b/VkNet.Tests/VkNet.Tests.csproj index 415e4265b..28c482aeb 100644 --- a/VkNet.Tests/VkNet.Tests.csproj +++ b/VkNet.Tests/VkNet.Tests.csproj @@ -3,6 +3,7 @@ false net8.0 latest + CS0618 diff --git a/VkNet/Utils/PerformanceActivator.cs b/VkNet/Utils/PerformanceActivator.cs index e1009c077..70a6f6f4a 100644 --- a/VkNet/Utils/PerformanceActivator.cs +++ b/VkNet/Utils/PerformanceActivator.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -14,8 +13,8 @@ namespace VkNet.Utils; public static class PerformanceActivator { private delegate T ObjectActivator(params object[] args); - - /// + + /// internal static TResult CreateInstance(params object[] args) where TResult : class => CreateInstance(_ => true, args); @@ -26,7 +25,7 @@ internal static TResult CreateInstance(params object[] args) /// Параметры конструктора /// Возвращаемый тип /// Экземпляр класса - private static TResult CreateInstance(Func constructorFilter, params object[] args) + private static TResult CreateInstance(Predicate constructorFilter, params object[] args) where TResult : class => CreateInstance(typeof(TResult), constructorFilter, args); /// @@ -37,11 +36,10 @@ private static TResult CreateInstance(Func const /// Параметры конструктора /// Возвращаемый тип /// Экземпляр класса - internal static TResult CreateInstance(Type obj, Func constructorFilter, params object[] args) + internal static TResult CreateInstance(Type obj, Predicate constructorFilter, params object[] args) where TResult : class { - var ctor = obj.GetConstructors() - .FirstOrDefault(constructorFilter); + var ctor = Array.Find(obj.GetConstructors(), constructorFilter); if (ctor is null) { diff --git a/VkNet/Utils/Url.cs b/VkNet/Utils/Url.cs index 463606e0f..31d531be3 100644 --- a/VkNet/Utils/Url.cs +++ b/VkNet/Utils/Url.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.RegularExpressions; @@ -19,6 +20,7 @@ public static class Url /// /// The combined URL. /// + [SuppressMessage("Performance", "CA1866:Использовать перегрузку символов", Justification = "Не поддерживается в netstandard2.0")] public static string Combine(params string[] parts) { if (parts is null) diff --git a/VkNet/Utils/Utilities.cs b/VkNet/Utils/Utilities.cs index 87aed9257..4ec6c831a 100644 --- a/VkNet/Utils/Utilities.cs +++ b/VkNet/Utils/Utilities.cs @@ -111,6 +111,8 @@ public static string PrettyPrintJson(string json) { var jObject = json.ToJObject(); + + foreach (var key in keysToHide) { if (jObject.ContainsKey(key)) diff --git a/VkNet/Utils/VkErrorFactory.cs b/VkNet/Utils/VkErrorFactory.cs index 2fece9fe3..5d078a6e9 100644 --- a/VkNet/Utils/VkErrorFactory.cs +++ b/VkNet/Utils/VkErrorFactory.cs @@ -22,10 +22,9 @@ public static class VkErrorFactory /// public static VkApiMethodInvokeException Create(VkError error) { - var vkApiMethodInvokeExceptions = typeof(VkApiMethodInvokeException).Assembly - .GetTypes() - .FirstOrDefault(x => x.IsSubclassOf(typeof(VkApiMethodInvokeException)) - && HasErrorCode(x, error.ErrorCode)); + var vkApiMethodInvokeExceptions = Array.Find(typeof(VkApiMethodInvokeException).Assembly.GetTypes(), x => + x.IsSubclassOf(typeof(VkApiMethodInvokeException)) + && HasErrorCode(x, error.ErrorCode)); if (vkApiMethodInvokeExceptions is null) { diff --git a/VkNet/Utils/VkParameters.cs b/VkNet/Utils/VkParameters.cs index dd3429014..3d84413d4 100644 --- a/VkNet/Utils/VkParameters.cs +++ b/VkNet/Utils/VkParameters.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.Serialization; @@ -25,7 +26,6 @@ public VkParameters() /// protected VkParameters(SerializationInfo serializationInfo, StreamingContext streamingContext) { - } /// @@ -64,7 +64,9 @@ public void Add(string name, T value) { if (Utilities.IsStringEnum(value.GetType())) { - Add(name, value.ToString().ToSnakeCase()); + Add(name, value.ToString() + .ToSnakeCase()); + return; } @@ -151,6 +153,7 @@ public void Add(string name, T? nullableValue) /// /// Имя параметра запроса. /// Значение параметра. + [SuppressMessage("Minor Code Smell", "S6588", Justification = "Не поддерживается в netstandard2.0")] public void Add(string name, DateTime? nullableDateTime) { Remove(key: name); diff --git a/VkNet/Utils/VkResponse.cs b/VkNet/Utils/VkResponse.cs index b89c66427..2ca58824a 100644 --- a/VkNet/Utils/VkResponse.cs +++ b/VkNet/Utils/VkResponse.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Net; using JetBrains.Annotations; using Newtonsoft.Json.Linq; @@ -339,6 +340,7 @@ public static implicit operator DateTime(VkResponse response) /// /// Дата и время /// + [SuppressMessage("Minor Code Smell", "S6588", Justification = "Не поддерживается в netstandard2.0")] public static DateTime TimestampToDateTime(long unixTimeStamp) { var dt = new DateTime(1970, 1, 1, 0, 0, diff --git a/VkNet/Utils/VkResponseEx.cs b/VkNet/Utils/VkResponseEx.cs index 6ae4081b1..ed28ec04d 100644 --- a/VkNet/Utils/VkResponseEx.cs +++ b/VkNet/Utils/VkResponseEx.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -31,14 +32,14 @@ public static Collection ToCollectionOf(this VkResponse response, Func()); + return new([]); } var responseArray = (VkResponseArray) response; if (responseArray is null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false. { - return new(new List()); + return new([]); } return responseArray.Select(selector) @@ -67,14 +68,14 @@ public static ReadOnlyCollection { if (response is null) { - return new(new List()); + return new([]); } var responseArray = (VkResponseArray) response; if (responseArray is null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false. { - return new(new List()); + return new([]); } return responseArray.Select(selector) @@ -94,14 +95,14 @@ public static ReadOnlyCollection { if (response is null) { - return new(new List()); + return new([]); } var responseArray = (VkResponseArray) response; if (responseArray is null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false. { - return new(new List()); + return new([]); } return responseArray.Select(x => x as T) @@ -118,7 +119,7 @@ public static ReadOnlyCollection /// Коллекция данных только для чтения. public static ReadOnlyCollection ToReadOnlyCollectionOf(this IEnumerable responses, Func selector) => responses is null - ? new(new List()) + ? new([]) : responses.Select(selector) .ToReadOnlyCollection(); @@ -136,14 +137,14 @@ public static List ToListOf(this VkResponse response, Func { if (response is null) { - return new(); + return []; } var responseArray = (VkResponseArray) response; if (responseArray is null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false. { - return new(); + return []; } return responseArray.Select(selector) @@ -181,7 +182,7 @@ public static VkCollection ToVkCollectionOf(this VkResponse response { if (response is null) { - return new(0, Enumerable.Empty()); + return new(0, []); } VkResponseArray data = response.ContainsKey(arrayName) @@ -217,6 +218,7 @@ public static T ToEnum(this VkResponse response) /// /// Признак валидности json /// + [SuppressMessage("Performance", "CA1866:Использовать перегрузку символов", Justification = "Не поддерживается в netstandard2.0")] public static bool IsValidJson(string input) { input = input.Trim(); diff --git a/VkNet/VkApi.cs b/VkNet/VkApi.cs index fc3195f3b..c9409d14b 100644 --- a/VkNet/VkApi.cs +++ b/VkNet/VkApi.cs @@ -1,7 +1,6 @@ // ReSharper disable once RedundantUsingDirective using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.Serialization; @@ -290,7 +289,7 @@ public T Call(string methodName, VkParameters parameters, bool skipAuthorizat var settings = new JsonSerializerSettings { - Converters = new List(), + Converters = [], ContractResolver = new DefaultContractResolver() { NamingStrategy = new SnakeCaseNamingStrategy() @@ -793,7 +792,7 @@ public int MaxCaptchaRecognitionCount /// public IStoreCategory Store { get; set; } - + /// public ICallsCategory Calls { get; set; }