This commit is contained in:
XorogVEVO 2021-11-28 11:28:59 +01:00
parent 800ec1a349
commit 72095914a9
2 changed files with 41 additions and 20 deletions

25
.editorconfig Normal file
View file

@ -0,0 +1,25 @@
[*.cs]
# CS1998: Async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.CS1998.severity = none
# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = none
# CA1822: Mark members as static
dotnet_diagnostic.CA1822.severity = none
# Default severity for all analyzer diagnostics
dotnet_analyzer_diagnostic.severity = none
# IDE0063: Use simple 'using' statement
csharp_prefer_simple_using_statement = false
# IDE0057: Use range operator
csharp_style_prefer_range_operator = false
# IDE0047: Remove unnecessary parentheses
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
# IDE0047: Remove unnecessary parentheses
dotnet_diagnostic.IDE0047.severity = none

View file

@ -106,15 +106,15 @@ public static class UniversalExtensions
/// <returns>The URL the redirect leads to</returns>
public static async Task<string> UnshortenUrl(string url)
{
HttpClient client = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = false });
HttpClient client = new(new HttpClientHandler() { AllowAutoRedirect = false });
var request = await client.GetAsync(url);
if (request.StatusCode != HttpStatusCode.Found ||
request.StatusCode != HttpStatusCode.Redirect ||
request.StatusCode != HttpStatusCode.RedirectKeepVerb ||
request.StatusCode != HttpStatusCode.RedirectMethod ||
request.StatusCode != HttpStatusCode.PermanentRedirect ||
request.StatusCode != HttpStatusCode.TemporaryRedirect)
if (request.StatusCode is HttpStatusCode.Found
or HttpStatusCode.Redirect
or HttpStatusCode.RedirectKeepVerb
or HttpStatusCode.RedirectMethod
or HttpStatusCode.PermanentRedirect
or HttpStatusCode.TemporaryRedirect)
{
if (request.Headers is not null && request.Headers.Location is not null)
return await UnshortenUrl(request.Headers.Location.AbsoluteUri);
@ -175,12 +175,10 @@ public static class UniversalExtensions
/// <returns></returns>
public static string ComputeSHA256Hash(string filePath)
{
using (SHA256 _SHA256 = SHA256.Create())
{
using (FileStream fileStream = File.OpenRead(filePath))
using SHA256 _SHA256 = SHA256.Create();
using FileStream fileStream = File.OpenRead(filePath);
return BitConverter.ToString(_SHA256.ComputeHash(fileStream)).Replace("-", "").ToLowerInvariant();
}
}
@ -316,7 +314,7 @@ public static class UniversalExtensions
{
foreach (char c in str)
{
if (c < '0' || c > '9')
if (c is < '0' or > '9')
return false;
}
@ -331,7 +329,7 @@ public static class UniversalExtensions
/// <param name="str"></param>
/// <returns></returns>
public static string GetAllDigits(this string str) =>
new String(str.Where(Char.IsDigit).ToArray());
new(str.Where(Char.IsDigit).ToArray());
}
public static class StringExt
@ -345,7 +343,7 @@ public static class StringExt
public static string Truncate(this string value, int maxLength)
{
if (string.IsNullOrEmpty(value)) return value;
return value.Length <= maxLength ? value : value.Substring(0, maxLength);
return value.Length <= maxLength ? value : value[ ..maxLength ];
}
@ -361,7 +359,7 @@ public static class StringExt
if (string.IsNullOrEmpty(value))
return value;
return value.Length <= maxLength ? value : $"{value.Substring(0, maxLength)}..";
return value.Length <= maxLength ? value : $"{value[ ..maxLength ]}..";
}
@ -389,9 +387,7 @@ public static class StringExt
/// <returns></returns>
public static string ComputeSHA256Hash(string str)
{
using (SHA256 _SHA256 = SHA256.Create())
{
using SHA256 _SHA256 = SHA256.Create();
return BitConverter.ToString(_SHA256.ComputeHash(Encoding.ASCII.GetBytes(str))).Replace("-", "").ToLowerInvariant();
}
}
}