Skip to content

Commit 152c42c

Browse files
committed
Исправляет некоторые предупреждения
1 parent 9d7f568 commit 152c42c

9 files changed

+34
-26
lines changed

VkNet.Tests/VkNet.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<IsPackable>false</IsPackable>
44
<TargetFramework>net8.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
6+
<NoWarn>CS0618</NoWarn>
67
</PropertyGroup>
78
<ItemGroup>
89
<PackageReference Include="FluentAssertions"/>

VkNet/Utils/PerformanceActivator.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Linq;
32
using System.Linq.Expressions;
43
using System.Reflection;
54

@@ -14,8 +13,8 @@ namespace VkNet.Utils;
1413
public static class PerformanceActivator
1514
{
1615
private delegate T ObjectActivator<out T>(params object[] args);
17-
18-
/// <inheritdoc cref="CreateInstance{TResult}(System.Func{System.Reflection.ConstructorInfo,bool}(System.Reflection.ConstructorInfo),object[])"/>
16+
17+
/// <inheritdoc cref="CreateInstance{TResult}(System.Predicate{System.Reflection.ConstructorInfo},object[])"/>
1918
internal static TResult CreateInstance<TResult>(params object[] args)
2019
where TResult : class => CreateInstance<TResult>(_ => true, args);
2120

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

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

4644
if (ctor is null)
4745
{

VkNet/Utils/Url.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Linq;
45
using System.Text.RegularExpressions;
56

@@ -19,6 +20,7 @@ public static class Url
1920
/// <returns>
2021
/// The combined URL.
2122
/// </returns>
23+
[SuppressMessage("Performance", "CA1866:Использовать перегрузку символов", Justification = "Не поддерживается в netstandard2.0")]
2224
public static string Combine(params string[] parts)
2325
{
2426
if (parts is null)

VkNet/Utils/Utilities.cs

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public static string PrettyPrintJson(string json)
111111
{
112112
var jObject = json.ToJObject();
113113

114+
115+
114116
foreach (var key in keysToHide)
115117
{
116118
if (jObject.ContainsKey(key))

VkNet/Utils/VkErrorFactory.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ public static class VkErrorFactory
2222
/// </returns>
2323
public static VkApiMethodInvokeException Create(VkError error)
2424
{
25-
var vkApiMethodInvokeExceptions = typeof(VkApiMethodInvokeException).Assembly
26-
.GetTypes()
27-
.FirstOrDefault(x => x.IsSubclassOf(typeof(VkApiMethodInvokeException))
28-
&& HasErrorCode(x, error.ErrorCode));
25+
var vkApiMethodInvokeExceptions = Array.Find(typeof(VkApiMethodInvokeException).Assembly.GetTypes(), x =>
26+
x.IsSubclassOf(typeof(VkApiMethodInvokeException))
27+
&& HasErrorCode(x, error.ErrorCode));
2928

3029
if (vkApiMethodInvokeExceptions is null)
3130
{

VkNet/Utils/VkParameters.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Globalization;
45
using System.Runtime.Serialization;
56

@@ -25,7 +26,6 @@ public VkParameters()
2526
/// </summary>
2627
protected VkParameters(SerializationInfo serializationInfo, StreamingContext streamingContext)
2728
{
28-
2929
}
3030

3131
/// <inheritdoc />
@@ -64,7 +64,9 @@ public void Add<T>(string name, T value)
6464
{
6565
if (Utilities.IsStringEnum(value.GetType()))
6666
{
67-
Add(name, value.ToString().ToSnakeCase());
67+
Add(name, value.ToString()
68+
.ToSnakeCase());
69+
6870
return;
6971
}
7072

@@ -151,6 +153,7 @@ public void Add<T>(string name, T? nullableValue)
151153
/// </summary>
152154
/// <param name="name"> Имя параметра запроса. </param>
153155
/// <param name="nullableDateTime"> Значение параметра. </param>
156+
[SuppressMessage("Minor Code Smell", "S6588", Justification = "Не поддерживается в netstandard2.0")]
154157
public void Add(string name, DateTime? nullableDateTime)
155158
{
156159
Remove(key: name);

VkNet/Utils/VkResponse.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Net;
34
using JetBrains.Annotations;
45
using Newtonsoft.Json.Linq;
@@ -339,6 +340,7 @@ public static implicit operator DateTime(VkResponse response)
339340
/// <returns>
340341
/// Дата и время
341342
/// </returns>
343+
[SuppressMessage("Minor Code Smell", "S6588", Justification = "Не поддерживается в netstandard2.0")]
342344
public static DateTime TimestampToDateTime(long unixTimeStamp)
343345
{
344346
var dt = new DateTime(1970, 1, 1, 0, 0,

VkNet/Utils/VkResponseEx.cs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Diagnostics.CodeAnalysis;
45
using System.Linq;
56
using Newtonsoft.Json;
67
using Newtonsoft.Json.Linq;
@@ -31,14 +32,14 @@ public static Collection<T> ToCollectionOf<T>(this VkResponse response, Func<VkR
3132
{
3233
if (response is null)
3334
{
34-
return new(new List<T>());
35+
return new([]);
3536
}
3637

3738
var responseArray = (VkResponseArray) response;
3839

3940
if (responseArray is null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false.
4041
{
41-
return new(new List<T>());
42+
return new([]);
4243
}
4344

4445
return responseArray.Select(selector)
@@ -67,14 +68,14 @@ public static ReadOnlyCollection<T>
6768
{
6869
if (response is null)
6970
{
70-
return new(new List<T>());
71+
return new([]);
7172
}
7273

7374
var responseArray = (VkResponseArray) response;
7475

7576
if (responseArray is null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false.
7677
{
77-
return new(new List<T>());
78+
return new([]);
7879
}
7980

8081
return responseArray.Select(selector)
@@ -94,14 +95,14 @@ public static ReadOnlyCollection<T>
9495
{
9596
if (response is null)
9697
{
97-
return new(new List<T>());
98+
return new([]);
9899
}
99100

100101
var responseArray = (VkResponseArray) response;
101102

102103
if (responseArray is null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false.
103104
{
104-
return new(new List<T>());
105+
return new([]);
105106
}
106107

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

@@ -136,14 +137,14 @@ public static List<T> ToListOf<T>(this VkResponse response, Func<VkResponse, T>
136137
{
137138
if (response is null)
138139
{
139-
return new();
140+
return [];
140141
}
141142

142143
var responseArray = (VkResponseArray) response;
143144

144145
if (responseArray is null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false.
145146
{
146-
return new();
147+
return [];
147148
}
148149

149150
return responseArray.Select(selector)
@@ -181,7 +182,7 @@ public static VkCollection<T> ToVkCollectionOf<T>(this VkResponse response
181182
{
182183
if (response is null)
183184
{
184-
return new(0, Enumerable.Empty<T>());
185+
return new(0, []);
185186
}
186187

187188
VkResponseArray data = response.ContainsKey(arrayName)
@@ -217,6 +218,7 @@ public static T ToEnum<T>(this VkResponse response)
217218
/// <returns>
218219
/// Признак валидности json
219220
/// </returns>
221+
[SuppressMessage("Performance", "CA1866:Использовать перегрузку символов", Justification = "Не поддерживается в netstandard2.0")]
220222
public static bool IsValidJson(string input)
221223
{
222224
input = input.Trim();

VkNet/VkApi.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// ReSharper disable once RedundantUsingDirective
22
using System;
33
using System.Collections.Generic;
4-
using System.IO;
54
using System.Linq;
65
using System.Runtime.CompilerServices;
76
using System.Runtime.Serialization;
@@ -290,7 +289,7 @@ public T Call<T>(string methodName, VkParameters parameters, bool skipAuthorizat
290289

291290
var settings = new JsonSerializerSettings
292291
{
293-
Converters = new List<JsonConverter>(),
292+
Converters = [],
294293
ContractResolver = new DefaultContractResolver()
295294
{
296295
NamingStrategy = new SnakeCaseNamingStrategy()
@@ -793,7 +792,7 @@ public int MaxCaptchaRecognitionCount
793792

794793
/// <inheritdoc />
795794
public IStoreCategory Store { get; set; }
796-
795+
797796
/// <inheritdoc />
798797
public ICallsCategory Calls { get; set; }
799798

0 commit comments

Comments
 (0)