Skip to content

Commit 6d5bce0

Browse files
committed
Clean up ifdefs
1 parent 6ec439e commit 6d5bce0

20 files changed

+105
-88
lines changed

QRCoder.Xaml/XamlQRCode.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if NETFRAMEWORK || NET5_0_WINDOWS || NET6_0_WINDOWS
2-
using System;
1+
using System;
32
using System.Windows;
43
using System.Windows.Media;
54
using static QRCoder.QRCodeGenerator;
@@ -93,5 +92,3 @@ public static DrawingImage GetQRCode(string plainText, int pixelsPerModule, stri
9392
}
9493
}
9594
}
96-
97-
#endif

QRCoder/ArtQRCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
1+
#if SYSTEM_DRAWING
22

33
using System;
44
using System.Drawing;
@@ -9,7 +9,7 @@
99
// pull request raised to extend library used.
1010
namespace QRCoder
1111
{
12-
#if NET6_0_WINDOWS
12+
#if NET6_0_OR_GREATER
1313
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
1414
#endif
1515
public class ArtQRCode : AbstractQRCode, IDisposable
@@ -258,7 +258,7 @@ public enum BackgroundImageStyle
258258
}
259259
}
260260

261-
#if NET6_0_WINDOWS
261+
#if NET6_0_OR_GREATER
262262
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
263263
#endif
264264
public static class ArtQRCodeHelper

QRCoder/Base64QRCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
6262
return Convert.ToBase64String(pngData, Base64FormattingOptions.None);
6363
}
6464

65-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
65+
#if SYSTEM_DRAWING
6666
#pragma warning disable CA1416 // Validate platform compatibility
6767
var qr = new QRCode(QrCodeData);
6868
var base64 = string.Empty;
@@ -77,7 +77,7 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
7777
#endif
7878
}
7979

80-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
80+
#if SYSTEM_DRAWING
8181
#if NET6_0_OR_GREATER
8282
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
8383
#endif
@@ -93,7 +93,7 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
9393
}
9494
#endif
9595

96-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
96+
#if SYSTEM_DRAWING
9797
#if NET6_0_OR_GREATER
9898
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
9999
#endif

QRCoder/PayloadGenerator.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,14 +2516,10 @@ public override string ToString()
25162516
var cp = characterSet.ToString().Replace("_", "-");
25172517
var bytes = ToBytes();
25182518

2519-
#if !NET35_OR_GREATER && !NETSTANDARD1_3_OR_GREATER
2519+
#if NETCOREAPP
25202520
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
25212521
#endif
2522-
#if NETSTANDARD1_3
2523-
return Encoding.GetEncoding(cp).GetString(bytes,0,bytes.Length);
2524-
#else
2525-
return Encoding.GetEncoding(cp).GetString(bytes);
2526-
#endif
2522+
return Encoding.GetEncoding(cp).GetString(bytes, 0, bytes.Length);
25272523
}
25282524

25292525
/// <summary>
@@ -2536,7 +2532,7 @@ public byte[] ToBytes()
25362532
{
25372533
//Setup byte encoder
25382534
//Encode return string as byte[] with correct CharacterSet
2539-
#if !NET35_OR_GREATER
2535+
#if !NETFRAMEWORK // -- why different ifdef than line 2519? --
25402536
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
25412537
#endif
25422538
var cp = this.characterSet.ToString().Replace("_", "-");

QRCoder/PdfByteQRCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
1+
#if SYSTEM_DRAWING
22
using System;
33
using System.Collections.Generic;
44
using System.Drawing.Imaging;
@@ -11,7 +11,7 @@
1111
namespace QRCoder
1212
{
1313

14-
#if NET6_0_WINDOWS
14+
#if NET6_0_OR_GREATER
1515
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
1616
#endif
1717
// ReSharper disable once InconsistentNaming
@@ -213,7 +213,7 @@ public byte[] GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string li
213213
}
214214
}
215215

216-
#if NET6_0_WINDOWS
216+
#if NET6_0_OR_GREATER
217217
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
218218
#endif
219219
public static class PdfByteQRCodeHelper

QRCoder/QRCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
1+
#if SYSTEM_DRAWING
22
using System;
33
using System.Drawing;
44
using System.Drawing.Drawing2D;
55
using static QRCoder.QRCodeGenerator;
66

77
namespace QRCoder
88
{
9-
#if NET6_0_WINDOWS
9+
#if NET6_0_OR_GREATER
1010
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
1111
#endif
1212
public class QRCode : AbstractQRCode, IDisposable
@@ -128,7 +128,7 @@ internal GraphicsPath CreateRoundedRectanglePath(RectangleF rect, int cornerRadi
128128
}
129129
}
130130

131-
#if NET6_0_WINDOWS
131+
#if NET6_0_OR_GREATER
132132
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
133133
#endif
134134
public static class QRCodeHelper

QRCoder/QRCodeData.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ public QRCodeData(int version)
2121
for (var i = 0; i < size; i++)
2222
this.ModuleMatrix.Add(new BitArray(size));
2323
}
24-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
24+
25+
[Obsolete("This constructor will be removed in version 2.0.0.")]
2526
public QRCodeData(string pathToRawData, Compression compressMode) : this(File.ReadAllBytes(pathToRawData), compressMode)
2627
{
2728
}
28-
#endif
29+
2930
public QRCodeData(byte[] rawData, Compression compressMode)
3031
{
3132
var bytes = new List<byte>(rawData);
@@ -154,12 +155,11 @@ public byte[] GetRawData(Compression compressMode)
154155
return rawData;
155156
}
156157

157-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
158+
[Obsolete("This constructor will be removed in version 2.0.0.")]
158159
public void SaveRawData(string filePath, Compression compressMode)
159160
{
160161
File.WriteAllBytes(filePath, GetRawData(compressMode));
161162
}
162-
#endif
163163

164164
public int Version { get; private set; }
165165

QRCoder/QRCodeGenerator.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,7 @@ private static string ConvertToIso8859(string value, string Iso = "ISO-8859-2")
11071107
Encoding utf8 = Encoding.UTF8;
11081108
byte[] utfBytes = utf8.GetBytes(value);
11091109
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
1110-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
11111110
return iso.GetString(isoBytes);
1112-
#else
1113-
return iso.GetString(isoBytes, 0, isoBytes.Length);
1114-
#endif
11151111
}
11161112

11171113
private static string PlainTextToBinaryByte(string plainText, EciMode eciMode, bool utf8BOM, bool forceUtf8)

QRCoder/QRCoder.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>net35;net40;netstandard1.3;netstandard2.0;net5.0;net5.0-windows;net6.0;net6.0-windows</TargetFrameworks>
55
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
6+
<DefineConstants Condition="'$(TargetFramework)' != 'net6.0' AND '$(TargetFramework)' != 'netstandard1.3'">$(DefineConstants);SYSTEM_DRAWING</DefineConstants>
67
<DefineConstants Condition="'$(TargetFramework)' == 'net5.0-windows'">$(DefineConstants);NET5_0_WINDOWS</DefineConstants>
78
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0-windows'">$(DefineConstants);NET6_0_WINDOWS</DefineConstants>
89
<CheckEolTargetFramework>false</CheckEolTargetFramework>
@@ -48,9 +49,10 @@
4849
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net5.0' or '$(TargetFramework)' == 'net5.0-windows' ">
4950
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
5051
</ItemGroup>
51-
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-windows' ">
52-
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
53-
</ItemGroup>
52+
53+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-windows' ">
54+
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
55+
</ItemGroup>
5456

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

QRCoder/SvgQRCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0_OR_GREATER
1+
#if !NETSTANDARD1_3
22
using QRCoder.Extensions;
33
using System;
44
using System.Collections;
@@ -267,14 +267,14 @@ public class SvgLogo
267267
private object _logoRaw;
268268
private bool _isEmbedded;
269269

270-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
270+
#if SYSTEM_DRAWING
271271
/// <summary>
272272
/// Create a logo object to be used in SvgQRCode renderer
273273
/// </summary>
274274
/// <param name="iconRasterized">Logo to be rendered as Bitmap/rasterized graphic</param>
275275
/// <param name="iconSizePercent">Degree of percentage coverage of the QR code by the logo</param>
276276
/// <param name="fillLogoBackground">If true, the background behind the logo will be cleaned</param>
277-
#if NET6_0_WINDOWS
277+
#if NET6_0_OR_GREATER
278278
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
279279
#endif
280280
public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true)

0 commit comments

Comments
 (0)