Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
80 changes: 80 additions & 0 deletions QRCoder/Attributes/InterpolatedStringHandlerAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#if !NET6_0_OR_GREATER
namespace System.Runtime.CompilerServices;

/// <summary>
/// Indicates the attributed type is an interpolated string handler.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
internal sealed class InterpolatedStringHandlerAttribute : Attribute
{
}

/// <summary>
/// Indicates which arguments an interpolated string handler passes through to the underlying handler constructor.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class.
/// </summary>
/// <param name="argument">The name of the argument that should be passed to the handler.</param>
public InterpolatedStringHandlerArgumentAttribute(string argument)
{
Arguments = new[] { argument };
}

/// <summary>
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class.
/// </summary>
/// <param name="argument1">The name of the first argument that should be passed to the handler.</param>
/// <param name="argument2">The name of the second argument that should be passed to the handler.</param>
public InterpolatedStringHandlerArgumentAttribute(string argument1, string argument2)
{
Arguments = new[] { argument1, argument2 };
}

/// <summary>
/// Gets the arguments that should be passed to the handler.
/// </summary>
public string[] Arguments { get; }
}

/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="CompilerFeatureRequiredAttribute"/> class.
/// </summary>
/// <param name="featureName">The name of the compiler feature.</param>
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}

/// <summary>
/// Gets the name of the compiler feature.
/// </summary>
public string FeatureName { get; }

/// <summary>
/// Gets a value that indicates whether the compiler can choose to allow access if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; set; }

/// <summary>
/// The feature name used for ref structs.
/// </summary>
#pragma warning disable IDE1006 // Must match the BCL constant names
public const string RefStructs = nameof(RefStructs);

/// <summary>
/// The feature name used for required members.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
#pragma warning restore IDE1006
}
#endif
20 changes: 18 additions & 2 deletions QRCoder/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace QRCoder;

Expand Down Expand Up @@ -67,6 +68,21 @@ internal static string ToString(this char c, CultureInfo _)
=> c.ToString();
#endif

/// <summary>
/// Appends an interpolated string using invariant culture formatting.
/// On .NET 6+ appends via the invariant-culture interpolated-string handler overload (no extra string allocation).
/// Must be a static method (not an extension) so the handler can reference the <paramref name="sb"/> parameter (CS8944).
/// </summary>
#if NET6_0_OR_GREATER
internal static void AppendInvariant(
StringBuilder sb,
[InterpolatedStringHandlerArgument(nameof(sb))] ref StringBuilder.AppendInterpolatedStringHandler handler)
=> sb.Append(CultureInfo.InvariantCulture, ref handler);
#else
internal static void AppendInvariant(StringBuilder sb, string value)
=> sb.Append(value);
#endif

/// <summary>
/// Appends an integer value to the StringBuilder using invariant culture formatting.
/// </summary>
Expand All @@ -75,7 +91,7 @@ internal static string ToString(this char c, CultureInfo _)
internal static void AppendInvariant(this StringBuilder sb, int num)
{
#if NET6_0_OR_GREATER
sb.Append(CultureInfo.InvariantCulture, $"{num}");
AppendInvariant(sb, $"{num}");
#else
#if HAS_SPAN
Span<char> buffer = stackalloc char[16];
Expand All @@ -97,7 +113,7 @@ internal static void AppendInvariant(this StringBuilder sb, int num)
internal static void AppendInvariant(this StringBuilder sb, float num)
{
#if NET6_0_OR_GREATER
sb.Append(CultureInfo.InvariantCulture, $"{num:G7}");
AppendInvariant(sb, $"{num:G7}");
#else
#if HAS_SPAN
Span<char> buffer = stackalloc char[16];
Expand Down
15 changes: 12 additions & 3 deletions QRCoder/PayloadGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ internal static bool IsValidIban(string iban)

//Check IBAN checksum
var checksumValid = false;
var sum = $"{ibanCleared.Substring(4)}{ibanCleared.Substring(0, 4)}".ToCharArray().Aggregate("", (current, c) => current + (char.IsLetter(c) ? (c - 55).ToString(CultureInfo.InvariantCulture) : c.ToString(CultureInfo.InvariantCulture)));
var sumChars = $"{ibanCleared.Substring(4)}{ibanCleared.Substring(0, 4)}".ToCharArray();
var sumBuilder = new StringBuilder(sumChars.Length * 2);
foreach (var c in sumChars)
{
if (char.IsLetter(c))
sumBuilder.Append((c - 55).ToString(CultureInfo.InvariantCulture));
else
sumBuilder.Append(c);
}
var sum = sumBuilder.ToString();
int m = 0;
for (int i = 0; i < (int)Math.Ceiling((sum.Length - 2) / 7d); i++)
{
Expand All @@ -33,7 +42,7 @@ internal 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(CultureInfo.InvariantCulture)) + 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 Expand Up @@ -112,7 +121,7 @@ private static string EscapeInput(string inp, bool simple = false)
}
foreach (var c in forbiddenChars)
{
inp = inp.Replace(c.ToString(), "\\" + c);
inp = inp.Replace(c.ToString(), $"\\{c}");
}
return inp;
}
Expand Down
58 changes: 29 additions & 29 deletions QRCoder/PayloadGenerator/BezahlCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
_name = name;

//Limit reason length depending on payment type
//140 chars for SEPA payments and 27 chars for others
//140 chars for SEPA payments and 27 chars for others
var reasonLength = authority == AuthorityType.periodicsinglepaymentsepa || authority == AuthorityType.singledirectdebitsepa || authority == AuthorityType.singlepaymentsepa || (authority == AuthorityType.contact_v2 && newWayFilled) ? 140 : 27;
if (reason.Length > reasonLength)
throw new BezahlCodeException($"Reasons texts have to be shorter than {reasonLength + 1} chars.");
Expand Down Expand Up @@ -246,9 +246,8 @@
/// <inheritdoc/>
public override string ToString()
{
var bezahlCodePayload = $"bank://{_authority}?";

bezahlCodePayload += $"name={Uri.EscapeDataString(_name)}&";
var bezahlCodePayload = new StringBuilder($"bank://{_authority}?");
StringExtensions.AppendInvariant(bezahlCodePayload,$"name={Uri.EscapeDataString(_name)}&");

Check failure on line 250 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 250 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 250 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 250 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 250 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 250 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 250 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

if (_authority != AuthorityType.contact && _authority != AuthorityType.contact_v2)
{
Expand All @@ -257,44 +256,44 @@
if (_authority == AuthorityType.periodicsinglepayment || _authority == AuthorityType.singledirectdebit || _authority == AuthorityType.singlepayment)
#pragma warning restore CS0618
{
bezahlCodePayload += $"account={_account}&";
bezahlCodePayload += $"bnc={_bnc}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"account={_account}&");

Check failure on line 259 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 259 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 259 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 259 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 259 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 259 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 259 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
StringExtensions.AppendInvariant(bezahlCodePayload,$"bnc={_bnc}&");

Check failure on line 260 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 260 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 260 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 260 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 260 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 260 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 260 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
if (_postingKey > 0)
bezahlCodePayload += $"postingkey={_postingKey}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"postingkey={_postingKey}&");

Check failure on line 262 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 262 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 262 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 262 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 262 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 262 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 262 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
}
else
{
bezahlCodePayload += $"iban={_iban}&";
bezahlCodePayload += $"bic={_bic}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"iban={_iban}&");

Check failure on line 266 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 266 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 266 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 266 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 266 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 266 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 266 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
StringExtensions.AppendInvariant(bezahlCodePayload,$"bic={_bic}&");

Check failure on line 267 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 267 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 267 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 267 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 267 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 267 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 267 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

if (!string.IsNullOrEmpty(_sepaReference))
bezahlCodePayload += $"separeference={Uri.EscapeDataString(_sepaReference)}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"separeference={Uri.EscapeDataString(_sepaReference)}&");

Check failure on line 270 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 270 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 270 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 270 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 270 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 270 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 270 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

if (_authority == AuthorityType.singledirectdebitsepa)
{
if (!string.IsNullOrEmpty(_creditorId))
bezahlCodePayload += $"creditorid={Uri.EscapeDataString(_creditorId)}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"creditorid={Uri.EscapeDataString(_creditorId)}&");

Check failure on line 275 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 275 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 275 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 275 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 275 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 275 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 275 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
if (!string.IsNullOrEmpty(_mandateId))
bezahlCodePayload += $"mandateid={Uri.EscapeDataString(_mandateId)}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"mandateid={Uri.EscapeDataString(_mandateId)}&");

Check failure on line 277 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 277 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 277 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 277 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 277 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 277 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 277 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
if (_dateOfSignature != DateTime.MinValue)
bezahlCodePayload += $"dateofsignature={_dateOfSignature.ToString("ddMMyyyy", CultureInfo.InvariantCulture)}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"dateofsignature={_dateOfSignature.ToString("ddMMyyyy", CultureInfo.InvariantCulture)}&");

Check failure on line 279 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 279 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 2.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 279 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 279 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET 5.0 Windows

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 279 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / additional-tests

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 279 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Core 3.1

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 279 in QRCoder/PayloadGenerator/BezahlCode.cs

View workflow job for this annotation

GitHub Actions / Test .NET Framework 4.6.2

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
}
}
bezahlCodePayload += string.Format(CultureInfo.InvariantCulture, "amount={0:0.00}&", _amount).Replace(".", ",");
bezahlCodePayload.Append(string.Format(CultureInfo.InvariantCulture, "amount={0:0.00}&", _amount).Replace(".", ","));

if (!string.IsNullOrEmpty(_reason))
bezahlCodePayload += $"reason={Uri.EscapeDataString(_reason)}&";
bezahlCodePayload += $"currency={_currency}&";
bezahlCodePayload += $"executiondate={_executionDate.ToString("ddMMyyyy", CultureInfo.InvariantCulture)}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"reason={Uri.EscapeDataString(_reason)}&");
StringExtensions.AppendInvariant(bezahlCodePayload,$"currency={_currency}&");
StringExtensions.AppendInvariant(bezahlCodePayload,$"executiondate={_executionDate.ToString("ddMMyyyy", CultureInfo.InvariantCulture)}&");
#pragma warning disable CS0618
if (_authority == AuthorityType.periodicsinglepayment || _authority == AuthorityType.periodicsinglepaymentsepa)
{
bezahlCodePayload += $"periodictimeunit={_periodicTimeunit}&";
bezahlCodePayload += $"periodictimeunitrotation={_periodicTimeunitRotation}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"periodictimeunit={_periodicTimeunit}&");
StringExtensions.AppendInvariant(bezahlCodePayload,$"periodictimeunitrotation={_periodicTimeunitRotation}&");
if (_periodicFirstExecutionDate != DateTime.MinValue)
bezahlCodePayload += $"periodicfirstexecutiondate={_periodicFirstExecutionDate.ToString("ddMMyyyy", CultureInfo.InvariantCulture)}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"periodicfirstexecutiondate={_periodicFirstExecutionDate.ToString("ddMMyyyy", CultureInfo.InvariantCulture)}&");
if (_periodicLastExecutionDate != DateTime.MinValue)
bezahlCodePayload += $"periodiclastexecutiondate={_periodicLastExecutionDate.ToString("ddMMyyyy", CultureInfo.InvariantCulture)}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"periodiclastexecutiondate={_periodicLastExecutionDate.ToString("ddMMyyyy", CultureInfo.InvariantCulture)}&");
}
#pragma warning restore CS0618
}
Expand All @@ -303,28 +302,29 @@
//Handle what is same for all contacts
if (_authority == AuthorityType.contact)
{
bezahlCodePayload += $"account={_account}&";
bezahlCodePayload += $"bnc={_bnc}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"account={_account}&");
StringExtensions.AppendInvariant(bezahlCodePayload,$"bnc={_bnc}&");
}
else if (_authority == AuthorityType.contact_v2)
{
if (!string.IsNullOrEmpty(_account) && !string.IsNullOrEmpty(_bnc))
{
bezahlCodePayload += $"account={_account}&";
bezahlCodePayload += $"bnc={_bnc}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"account={_account}&");
StringExtensions.AppendInvariant(bezahlCodePayload,$"bnc={_bnc}&");
}
else
{
bezahlCodePayload += $"iban={_iban}&";
bezahlCodePayload += $"bic={_bic}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"iban={_iban}&");
StringExtensions.AppendInvariant(bezahlCodePayload,$"bic={_bic}&");
}
}

if (!string.IsNullOrEmpty(_reason))
bezahlCodePayload += $"reason={Uri.EscapeDataString(_reason)}&";
StringExtensions.AppendInvariant(bezahlCodePayload,$"reason={Uri.EscapeDataString(_reason)}&");
}

return bezahlCodePayload.Trim('&');
string result = bezahlCodePayload.ToString();
return result.TrimEnd('&');
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions QRCoder/PayloadGenerator/BitcoinLikeCryptoCurrencyAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public override string ToString()

if (queryValues.Any(keyPair => !string.IsNullOrEmpty(keyPair.Value)))
{
query = "?" + string.Join("&", queryValues
query = $"?{string.Join("&", queryValues
.Where(keyPair => !string.IsNullOrEmpty(keyPair.Value))
.Select(keyPair => $"{keyPair.Key}={keyPair.Value}")
.ToArray());
.ToArray())}";
}

return $"{Enum.GetName(typeof(BitcoinLikeCryptoCurrencyType), _currencyType)!.ToLowerInvariant()}:{_address}{query}";
Expand Down
Loading
Loading