Skip to content

Commit

Permalink
Исправляет некоторые предупреждения
Browse files Browse the repository at this point in the history
  • Loading branch information
inyutin-maxim committed Nov 19, 2024
1 parent 9d7f568 commit 152c42c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 26 deletions.
1 change: 1 addition & 0 deletions VkNet.Tests/VkNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<IsPackable>false</IsPackable>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<NoWarn>CS0618</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions"/>
Expand Down
12 changes: 5 additions & 7 deletions VkNet/Utils/PerformanceActivator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;

Expand All @@ -14,8 +13,8 @@ namespace VkNet.Utils;
public static class PerformanceActivator
{
private delegate T ObjectActivator<out T>(params object[] args);
/// <inheritdoc cref="CreateInstance{TResult}(System.Func{System.Reflection.ConstructorInfo,bool}(System.Reflection.ConstructorInfo),object[])"/>

/// <inheritdoc cref="CreateInstance{TResult}(System.Predicate{System.Reflection.ConstructorInfo},object[])"/>
internal static TResult CreateInstance<TResult>(params object[] args)
where TResult : class => CreateInstance<TResult>(_ => true, args);

Expand All @@ -26,7 +25,7 @@ internal static TResult CreateInstance<TResult>(params object[] args)
/// <param name="args">Параметры конструктора</param>
/// <typeparam name="TResult">Возвращаемый тип</typeparam>
/// <returns>Экземпляр класса <typeparamref name="TResult"/></returns>
private static TResult CreateInstance<TResult>(Func<ConstructorInfo, bool> constructorFilter, params object[] args)
private static TResult CreateInstance<TResult>(Predicate<ConstructorInfo> constructorFilter, params object[] args)
where TResult : class => CreateInstance<TResult>(typeof(TResult), constructorFilter, args);

/// <summary>
Expand All @@ -37,11 +36,10 @@ private static TResult CreateInstance<TResult>(Func<ConstructorInfo, bool> const
/// <param name="args">Параметры конструктора</param>
/// <typeparam name="TResult">Возвращаемый тип</typeparam>
/// <returns>Экземпляр класса <typeparamref name="TResult"/></returns>
internal static TResult CreateInstance<TResult>(Type obj, Func<ConstructorInfo, bool> constructorFilter, params object[] args)
internal static TResult CreateInstance<TResult>(Type obj, Predicate<ConstructorInfo> constructorFilter, params object[] args)
where TResult : class
{
var ctor = obj.GetConstructors()
.FirstOrDefault(constructorFilter);
var ctor = Array.Find(obj.GetConstructors(), constructorFilter);

if (ctor is null)
{
Expand Down
2 changes: 2 additions & 0 deletions VkNet/Utils/Url.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.RegularExpressions;

Expand All @@ -19,6 +20,7 @@ public static class Url
/// <returns>
/// The combined URL.
/// </returns>
[SuppressMessage("Performance", "CA1866:Использовать перегрузку символов", Justification = "Не поддерживается в netstandard2.0")]
public static string Combine(params string[] parts)
{
if (parts is null)
Expand Down
2 changes: 2 additions & 0 deletions VkNet/Utils/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public static string PrettyPrintJson(string json)
{
var jObject = json.ToJObject();



foreach (var key in keysToHide)
{
if (jObject.ContainsKey(key))
Expand Down
7 changes: 3 additions & 4 deletions VkNet/Utils/VkErrorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public static class VkErrorFactory
/// </returns>
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)
{
Expand Down
7 changes: 5 additions & 2 deletions VkNet/Utils/VkParameters.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.Serialization;

Expand All @@ -25,7 +26,6 @@ public VkParameters()
/// </summary>
protected VkParameters(SerializationInfo serializationInfo, StreamingContext streamingContext)
{

}

/// <inheritdoc />
Expand Down Expand Up @@ -64,7 +64,9 @@ public void Add<T>(string name, T value)
{
if (Utilities.IsStringEnum(value.GetType()))
{
Add(name, value.ToString().ToSnakeCase());
Add(name, value.ToString()
.ToSnakeCase());

return;
}

Expand Down Expand Up @@ -151,6 +153,7 @@ public void Add<T>(string name, T? nullableValue)
/// </summary>
/// <param name="name"> Имя параметра запроса. </param>
/// <param name="nullableDateTime"> Значение параметра. </param>
[SuppressMessage("Minor Code Smell", "S6588", Justification = "Не поддерживается в netstandard2.0")]
public void Add(string name, DateTime? nullableDateTime)
{
Remove(key: name);
Expand Down
2 changes: 2 additions & 0 deletions VkNet/Utils/VkResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -339,6 +340,7 @@ public static implicit operator DateTime(VkResponse response)
/// <returns>
/// Дата и время
/// </returns>
[SuppressMessage("Minor Code Smell", "S6588", Justification = "Не поддерживается в netstandard2.0")]
public static DateTime TimestampToDateTime(long unixTimeStamp)
{
var dt = new DateTime(1970, 1, 1, 0, 0,
Expand Down
22 changes: 12 additions & 10 deletions VkNet/Utils/VkResponseEx.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,14 +32,14 @@ public static Collection<T> ToCollectionOf<T>(this VkResponse response, Func<VkR
{
if (response is null)
{
return new(new List<T>());
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<T>());
return new([]);
}

return responseArray.Select(selector)
Expand Down Expand Up @@ -67,14 +68,14 @@ public static ReadOnlyCollection<T>
{
if (response is null)
{
return new(new List<T>());
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<T>());
return new([]);
}

return responseArray.Select(selector)
Expand All @@ -94,14 +95,14 @@ public static ReadOnlyCollection<T>
{
if (response is null)
{
return new(new List<T>());
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<T>());
return new([]);
}

return responseArray.Select(x => x as T)
Expand All @@ -118,7 +119,7 @@ public static ReadOnlyCollection<T>
/// <returns> Коллекция данных только для чтения. </returns>
public static ReadOnlyCollection<T> ToReadOnlyCollectionOf<T>(this IEnumerable<VkResponse> responses, Func<VkResponse, T> selector) =>
responses is null
? new(new List<T>())
? new([])
: responses.Select(selector)
.ToReadOnlyCollection();

Expand All @@ -136,14 +137,14 @@ public static List<T> ToListOf<T>(this VkResponse response, Func<VkResponse, T>
{
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)
Expand Down Expand Up @@ -181,7 +182,7 @@ public static VkCollection<T> ToVkCollectionOf<T>(this VkResponse response
{
if (response is null)
{
return new(0, Enumerable.Empty<T>());
return new(0, []);
}

VkResponseArray data = response.ContainsKey(arrayName)
Expand Down Expand Up @@ -217,6 +218,7 @@ public static T ToEnum<T>(this VkResponse response)
/// <returns>
/// Признак валидности json
/// </returns>
[SuppressMessage("Performance", "CA1866:Использовать перегрузку символов", Justification = "Не поддерживается в netstandard2.0")]
public static bool IsValidJson(string input)
{
input = input.Trim();
Expand Down
5 changes: 2 additions & 3 deletions VkNet/VkApi.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -290,7 +289,7 @@ public T Call<T>(string methodName, VkParameters parameters, bool skipAuthorizat

var settings = new JsonSerializerSettings
{
Converters = new List<JsonConverter>(),
Converters = [],
ContractResolver = new DefaultContractResolver()
{
NamingStrategy = new SnakeCaseNamingStrategy()
Expand Down Expand Up @@ -793,7 +792,7 @@ public int MaxCaptchaRecognitionCount

/// <inheritdoc />
public IStoreCategory Store { get; set; }

/// <inheritdoc />
public ICallsCategory Calls { get; set; }

Expand Down

0 comments on commit 152c42c

Please sign in to comment.