Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
<SignAssembly>false</SignAssembly>
<Deterministic>true</Deterministic>

<!-- Enable analyzers; treat all warnings as errors; disable 'using directive is unnecessary' and XML comment warnings -->
<!-- Enable analyzers; treat all warnings as errors; disable 'using directive is unnecessary' and throw helper warnings -->
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);IDE0005</NoWarn>
<NoWarn>$(NoWarn);IDE0005;CA1510</NoWarn>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisMode>Recommended</AnalysisMode>
<AnalysisLevel>8-recommended</AnalysisLevel>
</PropertyGroup>

<!-- Include README for packable projects -->
Expand Down
13 changes: 12 additions & 1 deletion QRCoder/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public static bool IsNullOrWhiteSpace(
#endif
}

#if !NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
/// <summary>
/// Determines whether the beginning of this string instance matches the specified character.
/// </summary>
/// <param name="value">The string to check.</param>
/// <param name="c">The character to compare.</param>
/// <returns>true if value starts with c; otherwise, false.</returns>
internal static bool StartsWith(this string value, char c)
=> value.Length > 0 && value[0] == c;
#endif
Comment thread
Shane32 marked this conversation as resolved.
Outdated

/// <summary>
/// Converts a hex color string to a byte array.
/// </summary>
Expand All @@ -38,7 +49,7 @@ public static bool IsNullOrWhiteSpace(
internal static byte[] HexColorToByteArray(this string colorString)
{
var offset = 0;
if (colorString.StartsWith("#", StringComparison.Ordinal))
if (colorString.StartsWith('#'))
offset = 1;
byte[] byteColor = new byte[(colorString.Length - offset) / 2];
for (int i = 0; i < byteColor.Length; i++)
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/PayloadGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static bool IsValidIban(string iban)
#if NET5_0_OR_GREATER
var n = string.Concat(i == 0 ? "" : m.ToString(CultureInfo.InvariantCulture), sum.AsSpan(start, Math.Min(9 - offset, sum.Length - start)));
#else
var n = (i == 0 ? "" : m.ToString()) + sum.Substring(start, Math.Min(9 - offset, sum.Length - start));
var n = (i == 0 ? "" : m.ToString(CultureInfo.InvariantCulture)) + sum.Substring(start, Math.Min(9 - offset, sum.Length - start));
#endif
if (!int.TryParse(n, NumberStyles.Any, CultureInfo.InvariantCulture, out m))
break;
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/PayloadGenerator/BezahlCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public BezahlCode(AuthorityType authority, string name, string account, string b
if (authority == AuthorityType.periodicsinglepayment || authority == AuthorityType.periodicsinglepaymentsepa)
#pragma warning restore CS0618
{
if (periodicTimeunit.ToUpperInvariant() != "M" && periodicTimeunit.ToUpperInvariant() != "W")
if (!periodicTimeunit.Equals("M", StringComparison.OrdinalIgnoreCase) && !periodicTimeunit.Equals("W", StringComparison.OrdinalIgnoreCase))
throw new BezahlCodeException("The periodicTimeunit must be either 'M' (monthly) or 'W' (weekly).");
_periodicTimeunit = periodicTimeunit;
if (periodicTimeunitRotation < 1 || periodicTimeunitRotation > 52)
Expand Down
3 changes: 2 additions & 1 deletion QRCoder/PayloadGenerator/ContactData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static partial class PayloadGenerator
/// </summary>
public class ContactData : Payload
{
private static readonly char[] _trimChars = { '\r', '\n' };
private readonly string _firstname;
private readonly string _lastname;
private readonly string? _nickname;
Expand Down Expand Up @@ -152,7 +153,7 @@ public override string ToString()
payload += $"URL:{_website}\r\n";
if (!string.IsNullOrEmpty(_nickname))
payload += $"NICKNAME:{_nickname}\r\n";
payload = payload.Trim(new char[] { '\r', '\n' });
payload = payload.Trim(_trimChars);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/PayloadGenerator/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override string ToString()
parts.Add("subject=" + Uri.EscapeDataString(_subject));
if (!string.IsNullOrEmpty(_message))
parts.Add("body=" + Uri.EscapeDataString(_message));
var queryString = parts.Any() ? $"?{string.Join("&", parts.ToArray())}" : "";
var queryString = parts.Count > 0 ? $"?{string.Join("&", parts.ToArray())}" : "";
return $"mailto:{_mailReceiver}{queryString}";
case MailEncoding.MATMSG:
return $"MATMSG:TO:{_mailReceiver};SUB:{EscapeInput(_subject ?? "")};BODY:{EscapeInput(_message ?? "")};;";
Expand Down
6 changes: 3 additions & 3 deletions QRCoder/PayloadGenerator/RussiaPaymentOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private List<string> GetOptionalFieldsAsList()
.Select(field =>
{
var objValue = field.GetValue(_oFields, null);
var value = field.PropertyType.Equals(typeof(DateTime?)) ? ((DateTime)objValue).ToString("dd.MM.yyyy") : objValue.ToString();
var value = field.PropertyType.Equals(typeof(DateTime?)) ? ((DateTime)objValue).ToString("dd.MM.yyyy", CultureInfo.InvariantCulture) : objValue.ToString();
return $"{field.Name}={value}";
})
.ToList();
Expand Down Expand Up @@ -176,7 +176,7 @@ private List<string> GetMandatoryFieldsAsList()
.Select(field =>
{
var objValue = field.GetValue(_mFields);
var value = field.FieldType.Equals(typeof(DateTime?)) ? ((DateTime)objValue).ToString("dd.MM.yyyy") : objValue.ToString();
var value = field.FieldType.Equals(typeof(DateTime?)) ? ((DateTime)objValue).ToString("dd.MM.yyyy", CultureInfo.InvariantCulture) : objValue.ToString();
return $"{field.Name}={value}";
})
.ToList();
Expand Down Expand Up @@ -224,7 +224,7 @@ private static string ValidateInput(string input, string fieldname, string[] pat
return input;
}

private class MandatoryFields
private sealed class MandatoryFields
{
public string Name = null!;
public string PersonalAcc = null!;
Expand Down
4 changes: 4 additions & 0 deletions QRCoder/QRCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,9 +1231,13 @@ static int[] GetNotUniqueExponents(Polynom list)
var dic = new Dictionary<int, bool>(list.Count);
foreach (var row in list)
{
#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
if (!dic.TryAdd(row.Exponent, false))
#else
if (!dic.ContainsKey(row.Exponent))
dic.Add(row.Exponent, false);
else
#endif
dic[row.Exponent] = true;
}
Comment thread
Shane32 marked this conversation as resolved.

Expand Down
2 changes: 1 addition & 1 deletion QRCoder/SvgQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private static int GetTransparency(string colorHex)
return 0; // Fully transparent

// Check for hex color with alpha channel
if (colorHex.StartsWith("#", StringComparison.Ordinal))
if (colorHex.StartsWith('#'))
{
// #RRGGBBAA format (9 characters)
if (colorHex.Length == 9)
Expand Down
2 changes: 1 addition & 1 deletion QRCoderConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace QRCoderConsole;
#if NET6_0 && WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
internal class MainClass
internal sealed class MainClass
{
public static void Main(string[] args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void ShouldMatchApproved(this byte[] actual, string fileExtension,
var declaringType = currentMethod?.DeclaringType;

// Check if the declaring type has the ShouldlyMethods attribute
var hasShouldlyAttribute = declaringType?.GetCustomAttributes(typeof(ShouldlyMethodsAttribute), false).Any() ?? false;
var hasShouldlyAttribute = declaringType?.GetCustomAttributes(typeof(ShouldlyMethodsAttribute), false).Length > 0;

// If this method is NOT in a ShouldlyMethods class, use it
if (!hasShouldlyAttribute)
Expand Down
2 changes: 1 addition & 1 deletion QRCoderTests/QRCoderTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<DefineConstants Condition="'$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net6.0-windows'">$(DefineConstants);TEST_XAML</DefineConstants>
<SuppressTfmSupportBuildErrors>true</SuppressTfmSupportBuildErrors>
<RuntimeFrameworkVersion Condition="'$(TargetFramework)' == 'netcoreapp2.1'">2.1.30</RuntimeFrameworkVersion>
<NoWarn>$(NoWarn);CA1707;CA1416</NoWarn>
<NoWarn>$(NoWarn);CA1707;CA1416;CA1850</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion QRCoderTests/QRGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ void Verify(QRCodeGenerator.ECCLevel eccLevel, string expected)
string Encode(QRCodeData qrData) => string.Join("", qrData.ModuleMatrix.Select(x => x.ToBitString()).ToArray());
}

private class SamplePayload : PayloadGenerator.Payload
private sealed class SamplePayload : PayloadGenerator.Payload
{
private readonly string _data;
private readonly QRCodeGenerator.ECCLevel _eccLevel;
Expand Down