Skip to content

Commit e25c521

Browse files
authored
Add NRT metadata (#559)
2 parents ba16519 + b15d28b commit e25c521

33 files changed

+585
-551
lines changed

QRCoder/AbstractQRCode.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public abstract class AbstractQRCode
55
protected QRCodeData QrCodeData { get; set; }
66

77
protected AbstractQRCode() {
8+
this.QrCodeData = null!;
89
}
910

1011
protected AbstractQRCode(QRCodeData data) {
@@ -22,7 +23,7 @@ virtual public void SetQRCodeData(QRCodeData data) {
2223
public void Dispose()
2324
{
2425
this.QrCodeData?.Dispose();
25-
this.QrCodeData = null;
26+
this.QrCodeData = null!;
2627
}
2728
}
2829
}

QRCoder/ArtQRCode.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Bitmap GetGraphic(int pixelsPerModule)
4040
/// </summary>
4141
/// <param name="backgroundImage">A bitmap object that will be used as background picture</param>
4242
/// <returns>QRCode graphic as bitmap</returns>
43-
public Bitmap GetGraphic(Bitmap backgroundImage = null)
43+
public Bitmap GetGraphic(Bitmap? backgroundImage = null)
4444
{
4545
return this.GetGraphic(10, Color.Black, Color.White, Color.Transparent, backgroundImage: backgroundImage);
4646
}
@@ -59,9 +59,9 @@ public Bitmap GetGraphic(Bitmap backgroundImage = null)
5959
/// <param name="backgroundImageStyle">Style of the background image (if set). Fill=spanning complete graphic; DataAreaOnly=Don't paint background into quietzone</param>
6060
/// <param name="finderPatternImage">Optional image that should be used instead of the default finder patterns</param>
6161
/// <returns>QRCode graphic as bitmap</returns>
62-
public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, Bitmap backgroundImage = null, double pixelSizeFactor = 1,
62+
public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, Bitmap? backgroundImage = null, double pixelSizeFactor = 1,
6363
bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Dotted,
64-
BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap finderPatternImage = null)
64+
BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap? finderPatternImage = null)
6565
{
6666
if (pixelSizeFactor > 1)
6767
throw new Exception("The parameter pixelSize must be between 0 and 1. (0-100%)");
@@ -211,8 +211,6 @@ private bool IsPartOfFinderPattern(int x, int y, int numModules, int offset)
211211
/// <returns>Resized image as bitmap</returns>
212212
private Bitmap Resize(Bitmap image, int newSize)
213213
{
214-
if (image == null) return null;
215-
216214
float scale = Math.Min((float)newSize / image.Width, (float)newSize / image.Height);
217215
var scaledWidth = (int)(image.Width * scale);
218216
var scaledHeight = (int)(image.Height * scale);
@@ -284,9 +282,9 @@ public static class ArtQRCodeHelper
284282
/// <param name="finderPatternImage">Optional image that should be used instead of the default finder patterns</param>
285283
/// <returns>QRCode graphic as bitmap</returns>
286284
public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, ECCLevel eccLevel, bool forceUtf8 = false,
287-
bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap backgroundImage = null, double pixelSizeFactor = 1.0,
285+
bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap? backgroundImage = null, double pixelSizeFactor = 1.0,
288286
bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Flat,
289-
BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap finderPatternImage = null)
287+
BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap? finderPatternImage = null)
290288
{
291289
using (var qrGenerator = new QRCodeGenerator())
292290
using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#if !NETCOREAPP
2+
namespace System.Diagnostics.CodeAnalysis
3+
{
4+
/// <summary>
5+
/// Specifies that when a method returns System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.ReturnValue,
6+
/// the parameter will not be null even if the corresponding type allows it.
7+
/// </summary>
8+
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
9+
internal sealed class NotNullWhenAttribute : Attribute
10+
{
11+
/// <summary>
12+
/// Initializes the attribute with the specified return value condition.
13+
/// </summary>
14+
/// <param name="returnValue">If the method returns this value, the associated parameter will not be null.</param>
15+
public NotNullWhenAttribute(bool returnValue)
16+
{
17+
ReturnValue = returnValue;
18+
}
19+
20+
/// <summary>
21+
/// Gets the return value condition. If the method returns this value, the associated
22+
/// parameter will not be null.
23+
/// </summary>
24+
public bool ReturnValue { get; }
25+
}
26+
}
27+
#endif

QRCoder/Extensions/StringExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace QRCoder
24
{
35
internal static class StringExtensions
@@ -8,7 +10,9 @@ internal static class StringExtensions
810
/// <returns>
911
/// <see langword="true"/> if the <paramref name="value"/> is null, empty, or white space; otherwise, <see langword="false"/>.
1012
/// </returns>
11-
public static bool IsNullOrWhiteSpace(this string value)
13+
public static bool IsNullOrWhiteSpace(
14+
[NotNullWhen(false)]
15+
this string? value)
1216
{
1317
#if NET35
1418
if (value == null) return true;

QRCoder/Extensions/StringValueAttribute.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public static class CustomExtensions
4444
#if NET6_0_OR_GREATER
4545
[RequiresUnreferencedCode("This method uses reflection to examine the provided enum value.")]
4646
#endif
47-
public static string GetStringValue(this Enum value)
47+
public static string? GetStringValue(this Enum value)
4848
{
4949
#if NETSTANDARD1_3
5050
var fieldInfo = value.GetType().GetRuntimeField(value.ToString());
5151
#else
52-
var fieldInfo = value.GetType().GetField(value.ToString());
52+
var fieldInfo = value.GetType().GetField(value.ToString())!;
5353
#endif
5454
var attr = fieldInfo.GetCustomAttributes(typeof(StringValueAttribute), false) as StringValueAttribute[];
55-
return attr.Length > 0 ? attr[0].StringValue : null;
55+
return attr!.Length > 0 ? attr[0].StringValue : null;
5656
}
5757
}
5858
}

QRCoder/PayloadGenerator/BezahlCode.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class BezahlCode : Payload
99
{
1010
//BezahlCode specification: http://www.bezahlcode.de/wp-content/uploads/BezahlCode_TechDok.pdf
1111

12-
private readonly string name, iban, bic, account, bnc, sepaReference, reason, creditorId, mandateId, periodicTimeunit;
12+
private readonly string? iban, bic, account, bnc, sepaReference, creditorId, mandateId, periodicTimeunit;
13+
private readonly string name, reason;
1314
private readonly decimal amount;
1415
private readonly int postingKey, periodicTimeunitRotation;
1516
private readonly Currency currency;

QRCoder/PayloadGenerator/BitcoinAddress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public static partial class PayloadGenerator
44
{
55
public class BitcoinAddress : BitcoinLikeCryptoCurrencyAddress
66
{
7-
public BitcoinAddress(string address, double? amount, string label = null, string message = null)
7+
public BitcoinAddress(string address, double? amount, string? label = null, string? message = null)
88
: base(BitcoinLikeCryptoCurrencyType.Bitcoin, address, amount, label, message) { }
99
}
1010
}

QRCoder/PayloadGenerator/BitcoinCashAddress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public static partial class PayloadGenerator
44
{
55
public class BitcoinCashAddress : BitcoinLikeCryptoCurrencyAddress
66
{
7-
public BitcoinCashAddress(string address, double? amount, string label = null, string message = null)
7+
public BitcoinCashAddress(string address, double? amount, string? label = null, string? message = null)
88
: base(BitcoinLikeCryptoCurrencyType.BitcoinCash, address, amount, label, message) { }
99
}
1010
}

QRCoder/PayloadGenerator/BitcoinLikeCryptoCurrencyAddress.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public static partial class PayloadGenerator
1010
public class BitcoinLikeCryptoCurrencyAddress : Payload
1111
{
1212
private readonly BitcoinLikeCryptoCurrencyType currencyType;
13-
private readonly string address, label, message;
13+
private readonly string address;
14+
private readonly string? label, message;
1415
private readonly double? amount;
1516

1617
/// <summary>
@@ -21,7 +22,7 @@ public class BitcoinLikeCryptoCurrencyAddress : Payload
2122
/// <param name="amount">Amount of coins to transfer</param>
2223
/// <param name="label">Reference label</param>
2324
/// <param name="message">Referece text aka message</param>
24-
public BitcoinLikeCryptoCurrencyAddress(BitcoinLikeCryptoCurrencyType currencyType, string address, double? amount, string label = null, string message = null)
25+
public BitcoinLikeCryptoCurrencyAddress(BitcoinLikeCryptoCurrencyType currencyType, string address, double? amount, string? label = null, string? message = null)
2526
{
2627
this.currencyType = currencyType;
2728
this.address = address;
@@ -41,12 +42,12 @@ public BitcoinLikeCryptoCurrencyAddress(BitcoinLikeCryptoCurrencyType currencyTy
4142

4243
public override string ToString()
4344
{
44-
string query = null;
45+
string? query = null;
4546

46-
var queryValues = new KeyValuePair<string,string>[]{
47-
new KeyValuePair<string, string>(nameof(label), label),
48-
new KeyValuePair<string, string>(nameof(message), message),
49-
new KeyValuePair<string, string>(nameof(amount), amount.HasValue ? amount.Value.ToString("#.########", CultureInfo.InvariantCulture) : null)
47+
var queryValues = new KeyValuePair<string,string?>[]{
48+
new KeyValuePair<string, string?>(nameof(label), label),
49+
new KeyValuePair<string, string?>(nameof(message), message),
50+
new KeyValuePair<string, string?>(nameof(amount), amount.HasValue ? amount.Value.ToString("#.########", CultureInfo.InvariantCulture) : null)
5051
};
5152

5253
if (queryValues.Any(keyPair => !string.IsNullOrEmpty(keyPair.Value)))
@@ -57,7 +58,7 @@ public override string ToString()
5758
.ToArray());
5859
}
5960

60-
return $"{Enum.GetName(typeof(BitcoinLikeCryptoCurrencyType), currencyType).ToLower()}:{address}{query}";
61+
return $"{Enum.GetName(typeof(BitcoinLikeCryptoCurrencyType), currencyType)!.ToLower()}:{address}{query}";
6162
}
6263

6364
public enum BitcoinLikeCryptoCurrencyType

QRCoder/PayloadGenerator/CalendarEvent.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ public static partial class PayloadGenerator
66
{
77
public class CalendarEvent : Payload
88
{
9-
private readonly string subject, description, location, start, end;
9+
private readonly string subject, start, end;
10+
private readonly string? description, location;
1011
private readonly EventEncoding encoding;
1112

1213
/// <summary>
@@ -19,7 +20,7 @@ public class CalendarEvent : Payload
1920
/// <param name="end">End time (incl. UTC offset) of the event</param>
2021
/// <param name="allDayEvent">Is it a full day event?</param>
2122
/// <param name="encoding">Type of encoding (universal or iCal)</param>
22-
public CalendarEvent(string subject, string description, string location, DateTimeOffset start, DateTimeOffset end, bool allDayEvent, EventEncoding encoding = EventEncoding.Universal) : this(subject, description, location, start.UtcDateTime, end.UtcDateTime, allDayEvent, encoding)
23+
public CalendarEvent(string subject, string? description, string? location, DateTimeOffset start, DateTimeOffset end, bool allDayEvent, EventEncoding encoding = EventEncoding.Universal) : this(subject, description, location, start.UtcDateTime, end.UtcDateTime, allDayEvent, encoding)
2324
{
2425
}
2526

@@ -33,7 +34,7 @@ public CalendarEvent(string subject, string description, string location, DateTi
3334
/// <param name="end">End time of the event</param>
3435
/// <param name="allDayEvent">Is it a full day event?</param>
3536
/// <param name="encoding">Type of encoding (universal or iCal)</param>
36-
public CalendarEvent(string subject, string description, string location, DateTime start, DateTime end, bool allDayEvent, EventEncoding encoding = EventEncoding.Universal)
37+
public CalendarEvent(string subject, string? description, string? location, DateTime start, DateTime end, bool allDayEvent, EventEncoding encoding = EventEncoding.Universal)
3738
{
3839
this.subject = subject;
3940
this.description = description;

0 commit comments

Comments
 (0)