Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* add .NET 5.0 support #286

Merged
merged 1 commit into from
May 6, 2021
Merged
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
6 changes: 3 additions & 3 deletions QRCoder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.29911.84
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRCoder", "QRCoder\QRCoder.csproj", "{AA6BE23A-7813-4D2A-835E-B673631AE9F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRCoderConsole", "QRCoderConsole\QRCoderConsole.csproj", "{014F04C6-6099-4552-9A4F-D09C6E39D576}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRCoderConsole", "QRCoderConsole\QRCoderConsole.csproj", "{014F04C6-6099-4552-9A4F-D09C6E39D576}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRCoderDemo", "QRCoderDemo\QRCoderDemo.csproj", "{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}"
EndProject
Expand Down Expand Up @@ -55,12 +55,12 @@ Global
{014F04C6-6099-4552-9A4F-D09C6E39D576}.Release|x64.Build.0 = Release|Any CPU
{014F04C6-6099-4552-9A4F-D09C6E39D576}.Release|x86.ActiveCfg = Release|Any CPU
{014F04C6-6099-4552-9A4F-D09C6E39D576}.Release|x86.Build.0 = Release|Any CPU
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Debug|Any CPU.ActiveCfg = Debug|x86
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Debug|ARM.ActiveCfg = Debug|x86
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Debug|x64.ActiveCfg = Debug|x86
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Debug|x86.ActiveCfg = Debug|x86
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Debug|x86.Build.0 = Debug|x86
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Release|Any CPU.ActiveCfg = Release|x86
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Release|ARM.ActiveCfg = Release|x86
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Release|x64.ActiveCfg = Release|x86
{CA6DB0F5-DB6C-4DDD-8B5F-EF82FBB963E9}.Release|x86.ActiveCfg = Release|x86
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/Base64QRCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
using System;
using System.Drawing;
using System.Drawing.Imaging;
Expand Down
20 changes: 13 additions & 7 deletions QRCoder/PayloadGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,11 +1409,12 @@ public BezahlCode(AuthorityType authority, string name, string account, string b
}
else if (internalMode == 2)
{
#pragma warning disable CS0612
codebude marked this conversation as resolved.
Show resolved Hide resolved
if (authority != AuthorityType.periodicsinglepayment && authority != AuthorityType.singledirectdebit && authority != AuthorityType.singlepayment)
throw new BezahlCodeException("The constructor with 'account' and 'bnc' may only be used with 'non SEPA' authority types. Either choose another authority type or switch constructor.");
if (authority == AuthorityType.periodicsinglepayment && (string.IsNullOrEmpty(periodicTimeunit) || periodicTimeunitRotation == 0))
throw new BezahlCodeException("When using 'periodicsinglepayment' as authority type, the parameters 'periodicTimeunit' and 'periodicTimeunitRotation' must be set.");

#pragma warning restore CS0612
}
else if (internalMode == 3)
{
Expand All @@ -1437,8 +1438,10 @@ public BezahlCode(AuthorityType authority, string name, string account, string b
var newWayFilled = (!string.IsNullOrEmpty(iban) && !string.IsNullOrEmpty(bic));

//Non-SEPA payment types
#pragma warning disable CS0612
if (authority == AuthorityType.periodicsinglepayment || authority == AuthorityType.singledirectdebit || authority == AuthorityType.singlepayment || authority == AuthorityType.contact || (authority == AuthorityType.contact_v2 && oldWayFilled))
{
#pragma warning restore CS0612
if (!Regex.IsMatch(account.Replace(" ", ""), @"^[0-9]{1,9}$"))
throw new BezahlCodeException("The account entered isn't valid.");
this.account = account.Replace(" ", "").ToUpper();
Expand Down Expand Up @@ -1500,8 +1503,9 @@ public BezahlCode(AuthorityType authority, string name, string account, string b
throw new BezahlCodeException("Execution date must be today or in future.");
this.executionDate = (DateTime)executionDate;
}

#pragma warning disable CS0612
if (authority == AuthorityType.periodicsinglepayment || authority == AuthorityType.periodicsinglepaymentsepa)
#pragma warning restore CS0612
{
if (periodicTimeunit.ToUpper() != "M" && periodicTimeunit.ToUpper() != "W")
throw new BezahlCodeException("The periodicTimeunit must be either 'M' (monthly) or 'W' (weekly).");
Expand Down Expand Up @@ -1530,8 +1534,9 @@ public override string ToString()
if (authority != AuthorityType.contact && authority != AuthorityType.contact_v2)
{
//Handle what is same for all payments

#pragma warning disable CS0612
if (authority == AuthorityType.periodicsinglepayment || authority == AuthorityType.singledirectdebit || authority == AuthorityType.singlepayment)
#pragma warning restore CS0612
{
bezahlCodePayload += $"account={account}&";
bezahlCodePayload += $"bnc={bnc}&";
Expand All @@ -1552,7 +1557,7 @@ public override string ToString()
bezahlCodePayload += $"creditorid={ Uri.EscapeDataString(creditorId)}&";
if (!string.IsNullOrEmpty(mandateId))
bezahlCodePayload += $"mandateid={ Uri.EscapeDataString(mandateId)}&";
if (dateOfSignature != null)
if (dateOfSignature != DateTime.MinValue)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contructor takes nullable DateTimes ([...] , DateTime? dateOfSignature = null, [...] so I guess the dates should be checked against null or does ... != Datetime.MinValue also check for null?

Copy link
Author

@trivalik trivalik May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DateTime is a struct. It cannot be null. Also a warning appeared for this after add of .NET 5. I didn't check datatype of dateOfSignature. Nullable is not null, it is a class arround. So we have to check it by: dateOfSignature.HasValue
I will take care.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. The documentation states that for nullable types both, checking for null and checking for "HasValue" works: https://docs.microsoft.com/de-de/dotnet/csharp/language-reference/builtin-types/nullable-value-types
(Check second and third example.)

So I suggest we change the code to:

Suggested change
if (dateOfSignature != DateTime.MinValue)
if (dateOfSignature.HasValue && dateOfSignature >= DateTime.MinValue)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we have another issue here. The constructor does already convert the Nullable type to a regulare DateTime. In this case, nothing is assign and it will be the default value, which is probably DateTime.MinValue. This means there is no relation between your comment and this compare.

Copy link
Owner

@codebude codebude May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor does already convert the Nullable type to a regulare DateTime.

But it does so, only if dateOfSignature != null otherwise the conversion isn't run.

bezahlCodePayload += $"dateofsignature={dateOfSignature.ToString("ddMMyyyy")}&";
}
}
Expand All @@ -1562,16 +1567,17 @@ public override string ToString()
bezahlCodePayload += $"reason={ Uri.EscapeDataString(reason)}&";
bezahlCodePayload += $"currency={currency}&";
bezahlCodePayload += $"executiondate={executionDate.ToString("ddMMyyyy")}&";

#pragma warning disable CS0612
if (authority == AuthorityType.periodicsinglepayment || authority == AuthorityType.periodicsinglepaymentsepa)
{
bezahlCodePayload += $"periodictimeunit={periodicTimeunit}&";
bezahlCodePayload += $"periodictimeunitrotation={periodicTimeunitRotation}&";
if (periodicFirstExecutionDate != null)
if (periodicFirstExecutionDate != DateTime.MinValue)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contructor takes nullable DateTimes ([...] , DateTime? periodicFirstExecutionDate = null, [...] so I guess the dates should be checked against null or does ... != Datetime.MinValue also check for null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DateTime is a struct. It cannot be null. Also a warning appeared for this after add of .NET 5. I didn't check datatype of dateOfSignature. Nullable is not null, it is a class arround. So we have to check it by: dateOfSignature.HasValue
I will take care.

bezahlCodePayload += $"periodicfirstexecutiondate={periodicFirstExecutionDate.ToString("ddMMyyyy")}&";
if (periodicLastExecutionDate != null)
if (periodicLastExecutionDate != DateTime.MinValue)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contructor takes nullable DateTimes ([...] , DateTime? periodicLastExecutionDate = null, [...] so I guess the dates should be checked against null or does ... != Datetime.MinValue also check for null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DateTime is a struct. It cannot be null. Also a warning appeared for this after add of .NET 5. I didn't check datatype of dateOfSignature. Nullable is not null, it is a class arround. So we have to check it by: dateOfSignature.HasValue
I will take care.

bezahlCodePayload += $"periodiclastexecutiondate={periodicLastExecutionDate.ToString("ddMMyyyy")}&";
}
#pragma warning restore CS0612
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/PdfByteQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/PostscriptQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
using System;
using System.Drawing;
using static QRCoder.QRCodeGenerator;
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/QRCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
Expand Down
4 changes: 2 additions & 2 deletions QRCoder/QRCodeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public QRCodeData(int version)
for (var i = 0; i < size; i++)
this.ModuleMatrix.Add(new BitArray(size));
}
#if NETFRAMEWORK || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
public QRCodeData(string pathToRawData, Compression compressMode) : this(File.ReadAllBytes(pathToRawData), compressMode)
{
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public byte[] GetRawData(Compression compressMode)
return rawData;
}

#if NETFRAMEWORK || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
public void SaveRawData(string filePath, Compression compressMode)
{
File.WriteAllBytes(filePath, GetRawData(compressMode));
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/QRCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ private static string ConvertToIso8859(string value, string Iso = "ISO-8859-2")
Encoding utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(value);
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
#if NETFRAMEWORK || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
return iso.GetString(isoBytes);
#else
return iso.GetString(isoBytes, 0, isoBytes.Length);
Expand Down
11 changes: 6 additions & 5 deletions QRCoder/QRCoder.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net35;net40;netstandard1.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net35;net40;netstandard1.1;netstandard2.0;net5.0;net5.0-windows</TargetFrameworks>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<UseWindowsForms Condition="'$(TargetFramework)' == 'net5.0-windows'">true</UseWindowsForms>
<UseWPF Condition="'$(TargetFramework)' == 'net5.0-windows'">true</UseWPF>
<DefineConstants Condition="'$(TargetFramework)' == 'net5.0-windows'">$(DefineConstants);NET5_0_WINDOWS</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
codebude marked this conversation as resolved.
Show resolved Hide resolved
<NoWarn />
</PropertyGroup>

Expand All @@ -16,7 +18,6 @@
<Version>1.4.1</Version>
<Authors>Raffael Herrmann</Authors>
<AssemblyName>QRCoder</AssemblyName>
<RootNamespace>QRCoder</RootNamespace>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/codebude/QRCoder/</PackageProjectUrl>
<PackageIconUrl>http://code-bude.net/downloads/qrcoder-logo.png</PackageIconUrl>
Expand All @@ -30,12 +31,12 @@
<Reference Include="WindowsBase" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
</ItemGroup>

<PropertyGroup>
<FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'">$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
</PropertyGroup>

</Project>
</Project>
2 changes: 1 addition & 1 deletion QRCoder/SvgQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
using System;
using System.Collections;
using System.Drawing;
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/XamlQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK
#if NETFRAMEWORK || NET5_0_WINDOWS
using System;
using System.Windows;
using System.Windows.Media;
Expand Down
2 changes: 2 additions & 0 deletions QRCoderConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private static void GenerateQRCode(string payloadString, QRCodeGenerator.ECCLeve
}
}
break;
#if !NET5_0 && !NET5_0_WINDOWS
case SupportedImageFormat.Xaml:
using (var code = new XamlQRCode(data))
{
Expand All @@ -175,6 +176,7 @@ private static void GenerateQRCode(string payloadString, QRCodeGenerator.ECCLeve
}
}
break;
#endif
case SupportedImageFormat.Ps:
case SupportedImageFormat.Eps:
using (var code = new PostscriptQRCode(data))
Expand Down
3 changes: 1 addition & 2 deletions QRCoderConsole/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion ("1.0.*")]
[assembly: AssemblyVersion ("1.0.0.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

49 changes: 15 additions & 34 deletions QRCoderConsole/QRCoderConsole.csproj
Original file line number Diff line number Diff line change
@@ -1,52 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{014F04C6-6099-4552-9A4F-D09C6E39D576}</ProjectGuid>
<TargetFrameworks>net45;net5.0;net5.0-windows</TargetFrameworks>
<UseWindowsForms Condition="'$(TargetFramework)' == 'net5.0-windows'">true</UseWindowsForms>
<UseWPF Condition="'$(TargetFramework)' == 'net5.0-windows'">true</UseWPF>
<DefineConstants Condition="'$(TargetFramework)' == 'net5.0-windows'">$(DefineConstants);NET5_0_WINDOWS</DefineConstants>
<Externalconsole>true</Externalconsole>
<OutputType>Exe</OutputType>
<RootNamespace>QRCoderConsole</RootNamespace>
<AssemblyName>QRCoderConsole</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<Commandlineparameters>--in foo --out fooQR.png</Commandlineparameters>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net35' or '$(TargetFramework)' == 'net45' ">
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="NDesk.Options">
<HintPath>..\packages\NDesk.Options.0.2.1\lib\NDesk.Options.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SupportedImageFormat.cs" />
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<None Include="packages.config" />
<PackageReference Include="NDesk.Options" Version="0.2.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\QRCoder\QRCoder.csproj">
<Project>{aa6be23a-7813-4d2a-835e-b673631ae9f1}</Project>
Expand Down
4 changes: 0 additions & 4 deletions QRCoderConsole/packages.config

This file was deleted.

6 changes: 0 additions & 6 deletions QRCoderDemo/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,8 @@ private void btn_save_Click(object sender, EventArgs e)
}

pictureBoxQRCode.BackgroundImage.Save(fs, imageFormat);
fs.Close();
}
}





}

public void ExportToBmp(string path)
Expand Down
Loading