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
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
<!-- 6: ItemGroups - Directory.Build.targets -->

<PropertyGroup>
<!-- Set version information, C# language version, and default to non-packable project -->
<!-- Set version information, C# language version, enable NRT annotations, and default to non-packable project -->
<Version>1.6.1</Version>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>

<!-- Set common NuGet package properties -->
Expand Down
1 change: 0 additions & 1 deletion QRCoder/QRCoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<!-- Set essential properties -->
<TargetFrameworks>net35;net40;netstandard1.3;netstandard2.0;netstandard2.1;net5.0;net5.0-windows;net6.0;net6.0-windows</TargetFrameworks>
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>

<!-- Set NuGet package properties -->
Expand Down
6 changes: 3 additions & 3 deletions QRCoderConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void Main(string[] args)
var newLine = Environment.NewLine;
var setter = new OptionSetter();

string fileName = null, outputFileName = null, payload = null;
string? fileName = null, outputFileName = null, payload = null;

var eccLevel = QRCodeGenerator.ECCLevel.L;
var imageFormat = SupportedImageFormat.Png;
Expand Down Expand Up @@ -97,7 +97,7 @@ public static void Main(string[] args)
ShowHelp(optionSet);
}

string text = null;
string? text = null;
if (fileName != null)
{
var fileInfo = new FileInfo(fileName);
Expand All @@ -121,7 +121,7 @@ public static void Main(string[] args)
text = GetTextFromStream(stdin);
}

if (text != null)
if (text != null && outputFileName != null)
{
GenerateQRCode(text, eccLevel, outputFileName, imageFormat, pixelsPerModule, foregroundColor, backgroundColor);
}
Expand Down
7 changes: 3 additions & 4 deletions QRCoderDemo/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void buttonGenerate_Click(object sender, EventArgs e)

private void RenderQrCode()
{
string level = comboBoxECC.SelectedItem.ToString();
string level = comboBoxECC.SelectedItem?.ToString() ?? "L";
var eccLevel = (QRCodeGenerator.ECCLevel)(level == "L" ? 0 : level == "M" ? 1 : level == "Q" ? 2 : 3);
using var qrGenerator = new QRCodeGenerator();
using var qrCodeData = qrGenerator.CreateQrCode(textBoxQRCode.Text, eccLevel);
Expand All @@ -39,7 +39,7 @@ private void RenderQrCode()
pictureBoxQRCode.SizeMode = PictureBoxSizeMode.StretchImage;
}

private Bitmap GetIconBitmap()
private Bitmap? GetIconBitmap()
{
if (iconPath.Text.Length == 0)
{
Expand Down Expand Up @@ -98,8 +98,7 @@ private void btn_save_Click(object sender, EventArgs e)
// File type selected in the dialog box.
// NOTE that the FilterIndex property is one-based.

ImageFormat imageFormat = null;
imageFormat = saveFileDialog1.FilterIndex switch
ImageFormat? imageFormat = saveFileDialog1.FilterIndex switch
{
1 => ImageFormat.Bmp,
2 => ImageFormat.Png,
Expand Down
2 changes: 1 addition & 1 deletion QRCoderTests/Helpers/HelperFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static string GetAssemblyPath()
#if NET5_0_OR_GREATER
=> AppDomain.CurrentDomain.BaseDirectory;
#else
=> Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).Replace("file:\\", "");
=> Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)?.Replace("file:\\", "") ?? "";
#endif

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions QRCoderTests/PayloadGeneratorTests/IbanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void iban_validator_validate_german_iban()
var iban = "DE15268500010154131577";

var method = typeof(PayloadGenerator).GetMethod("IsValidIban", BindingFlags.NonPublic | BindingFlags.Static);
var result = (bool)method.Invoke(null, new object[] { iban });
var result = (bool)method!.Invoke(null, new object[] { iban })!;

result.ShouldBe<bool>(true);
}
Expand All @@ -31,7 +31,7 @@ public void iban_validator_validate_swiss_iban()
var iban = "CH1900767000U00121977";

var method = typeof(PayloadGenerator).GetMethod("IsValidIban", BindingFlags.NonPublic | BindingFlags.Static);
var result = (bool)method.Invoke(null, new object[] { iban });
var result = (bool)method!.Invoke(null, new object[] { iban })!;

result.ShouldBe<bool>(true);
}
Expand All @@ -42,7 +42,7 @@ public void iban_validator_invalidates_iban()
var iban = "DE29268500010154131577";

var method = typeof(PayloadGenerator).GetMethod("IsValidIban", BindingFlags.NonPublic | BindingFlags.Static);
var result = (bool)method.Invoke(null, new object[] { iban });
var result = (bool)method!.Invoke(null, new object[] { iban })!;

result.ShouldBe<bool>(false);
}
Expand All @@ -53,7 +53,7 @@ public void qriban_validator_validates_iban()
var iban = "CH2430043000000789012";

var method = typeof(PayloadGenerator).GetMethod("IsValidQRIban", BindingFlags.NonPublic | BindingFlags.Static);
var result = (bool)method.Invoke(null, new object[] { iban });
var result = (bool)method!.Invoke(null, new object[] { iban })!;

result.ShouldBe<bool>(true);
}
Expand All @@ -64,7 +64,7 @@ public void qriban_validator_invalidates_iban()
var iban = "CH3908704016075473007";

var method = typeof(PayloadGenerator).GetMethod("IsValidQRIban", BindingFlags.NonPublic | BindingFlags.Static);
var result = (bool)method.Invoke(null, new object[] { iban });
var result = (bool)method!.Invoke(null, new object[] { iban })!;

result.ShouldBe<bool>(false);
}
Expand Down
4 changes: 2 additions & 2 deletions QRCoderTests/PayloadGeneratorTests/RussiaPaymentOrderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ public void russiapayment_generator_should_throw_no_data_too_long_exception()
[Fact]
public void russiapayment_generator_should_throw_must_not_be_null_exception()
{
string account = null;
string? account = null;
var bic = "044525225";
var bankName = "ОАО | \"БАНК\"";
var name = "|@;:^_~{}!#$%&()*+,/";
var correspAcc = "30101810400000000225";

var exception = Should.Throw<PayloadGenerator.RussiaPaymentOrder.RussiaPaymentOrderException>(() => new PayloadGenerator.RussiaPaymentOrder(name, account, bankName, bic, correspAcc));
var exception = Should.Throw<PayloadGenerator.RussiaPaymentOrder.RussiaPaymentOrderException>(() => new PayloadGenerator.RussiaPaymentOrder(name, account!, bankName, bic, correspAcc));
exception.Message.ShouldBe($"The input for 'PersonalAcc' must not be null.");
}

Expand Down
16 changes: 8 additions & 8 deletions QRCoderTests/QRGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public void validate_antilogtable()

var checkString = string.Empty;
var tablesType = Type.GetType("QRCoder.QRCodeGenerator+GaloisField, QRCoder");
var gField = tablesType.GetField("_galoisFieldByExponentAlpha", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null).ShouldBeOfType<int[]>();
var gField = tablesType!.GetField("_galoisFieldByExponentAlpha", BindingFlags.NonPublic | BindingFlags.Static)!.GetValue(null).ShouldBeOfType<int[]>();
gField.Length.ShouldBe(256);
for (int i = 0; i < gField.Length; i++)
{
checkString += i + "," + gField[i] + ",:";
}
checkString.ShouldBe("0,1,:1,2,:2,4,:3,8,:4,16,:5,32,:6,64,:7,128,:8,29,:9,58,:10,116,:11,232,:12,205,:13,135,:14,19,:15,38,:16,76,:17,152,:18,45,:19,90,:20,180,:21,117,:22,234,:23,201,:24,143,:25,3,:26,6,:27,12,:28,24,:29,48,:30,96,:31,192,:32,157,:33,39,:34,78,:35,156,:36,37,:37,74,:38,148,:39,53,:40,106,:41,212,:42,181,:43,119,:44,238,:45,193,:46,159,:47,35,:48,70,:49,140,:50,5,:51,10,:52,20,:53,40,:54,80,:55,160,:56,93,:57,186,:58,105,:59,210,:60,185,:61,111,:62,222,:63,161,:64,95,:65,190,:66,97,:67,194,:68,153,:69,47,:70,94,:71,188,:72,101,:73,202,:74,137,:75,15,:76,30,:77,60,:78,120,:79,240,:80,253,:81,231,:82,211,:83,187,:84,107,:85,214,:86,177,:87,127,:88,254,:89,225,:90,223,:91,163,:92,91,:93,182,:94,113,:95,226,:96,217,:97,175,:98,67,:99,134,:100,17,:101,34,:102,68,:103,136,:104,13,:105,26,:106,52,:107,104,:108,208,:109,189,:110,103,:111,206,:112,129,:113,31,:114,62,:115,124,:116,248,:117,237,:118,199,:119,147,:120,59,:121,118,:122,236,:123,197,:124,151,:125,51,:126,102,:127,204,:128,133,:129,23,:130,46,:131,92,:132,184,:133,109,:134,218,:135,169,:136,79,:137,158,:138,33,:139,66,:140,132,:141,21,:142,42,:143,84,:144,168,:145,77,:146,154,:147,41,:148,82,:149,164,:150,85,:151,170,:152,73,:153,146,:154,57,:155,114,:156,228,:157,213,:158,183,:159,115,:160,230,:161,209,:162,191,:163,99,:164,198,:165,145,:166,63,:167,126,:168,252,:169,229,:170,215,:171,179,:172,123,:173,246,:174,241,:175,255,:176,227,:177,219,:178,171,:179,75,:180,150,:181,49,:182,98,:183,196,:184,149,:185,55,:186,110,:187,220,:188,165,:189,87,:190,174,:191,65,:192,130,:193,25,:194,50,:195,100,:196,200,:197,141,:198,7,:199,14,:200,28,:201,56,:202,112,:203,224,:204,221,:205,167,:206,83,:207,166,:208,81,:209,162,:210,89,:211,178,:212,121,:213,242,:214,249,:215,239,:216,195,:217,155,:218,43,:219,86,:220,172,:221,69,:222,138,:223,9,:224,18,:225,36,:226,72,:227,144,:228,61,:229,122,:230,244,:231,245,:232,247,:233,243,:234,251,:235,235,:236,203,:237,139,:238,11,:239,22,:240,44,:241,88,:242,176,:243,125,:244,250,:245,233,:246,207,:247,131,:248,27,:249,54,:250,108,:251,216,:252,173,:253,71,:254,142,:255,1,:");

var gField2 = tablesType.GetField("_galoisFieldByIntegerValue", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null).ShouldBeOfType<int[]>();
var gField2 = tablesType!.GetField("_galoisFieldByIntegerValue", BindingFlags.NonPublic | BindingFlags.Static)!.GetValue(null).ShouldBeOfType<int[]>();
gField2.Length.ShouldBe(256);
var checkString2 = string.Empty;
for (int i = 0; i < gField2.Length; i++)
Expand Down Expand Up @@ -388,8 +388,8 @@ public void validate_alphanumencdict()

var checkString = string.Empty;
var encoderType = Type.GetType("QRCoder.QRCodeGenerator+AlphanumericEncoder, QRCoder");
var gField = encoderType.GetField("_alphanumEncDict", BindingFlags.NonPublic | BindingFlags.Static);
foreach (var listitem in (Dictionary<char, int>)gField.GetValue(gen))
var gField = encoderType!.GetField("_alphanumEncDict", BindingFlags.NonPublic | BindingFlags.Static);
foreach (var listitem in (Dictionary<char, int>)gField!.GetValue(gen)!)
{
checkString += $"{listitem.Key},{listitem.Value}:";
}
Expand All @@ -401,7 +401,7 @@ public void can_recognize_enconding_numeric()
{
var gen = new QRCodeGenerator();
var method = gen.GetType().GetMethod("GetEncodingFromPlaintext", BindingFlags.NonPublic | BindingFlags.Static);
var result = (int)method.Invoke(gen, new object[] { "0123456789", false });
var result = (int)method!.Invoke(gen, new object[] { "0123456789", false })!;

result.ShouldBe(1);
}
Expand All @@ -412,7 +412,7 @@ public void can_recognize_enconding_alphanumeric()
{
var gen = new QRCodeGenerator();
var method = gen.GetType().GetMethod("GetEncodingFromPlaintext", BindingFlags.NonPublic | BindingFlags.Static);
var result = (int)method.Invoke(gen, new object[] { "0123456789ABC", false });
var result = (int)method!.Invoke(gen, new object[] { "0123456789ABC", false })!;

result.ShouldBe(2);
}
Expand All @@ -423,7 +423,7 @@ public void can_recognize_enconding_forced_bytemode()
{
var gen = new QRCodeGenerator();
var method = gen.GetType().GetMethod("GetEncodingFromPlaintext", BindingFlags.NonPublic | BindingFlags.Static);
var result = (int)method.Invoke(gen, new object[] { "0123456789", true });
var result = (int)method!.Invoke(gen, new object[] { "0123456789", true })!;

result.ShouldBe(4);
}
Expand All @@ -434,7 +434,7 @@ public void can_recognize_enconding_byte()
{
var gen = new QRCodeGenerator();
var method = gen.GetType().GetMethod("GetEncodingFromPlaintext", BindingFlags.NonPublic | BindingFlags.Static);
var result = (int)method.Invoke(gen, new object[] { "0123456789äöüß", false });
var result = (int)method!.Invoke(gen, new object[] { "0123456789äöüß", false })!;

result.ShouldBe(4);
}
Expand Down