diff --git a/.editorconfig b/.editorconfig index a4c561f8..f68d0e5c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -263,3 +263,4 @@ dotnet_diagnostic.IDE0005.severity = warning # Enforce formatting https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#rule-id-ide0055-fix-formatting dotnet_diagnostic.IDE0055.severity = error dotnet_diagnostic.IDE1006.severity = error +dotnet_diagnostic.IDE0022.severity = error diff --git a/QRCoder.Xaml/XamlQRCode.cs b/QRCoder.Xaml/XamlQRCode.cs index 0baefe60..a94ce002 100644 --- a/QRCoder.Xaml/XamlQRCode.cs +++ b/QRCoder.Xaml/XamlQRCode.cs @@ -15,9 +15,7 @@ public XamlQRCode() { } public XamlQRCode(QRCodeData data) : base(data) { } public DrawingImage GetGraphic(int pixelsPerModule) - { - return GetGraphic(pixelsPerModule, true); - } + => GetGraphic(pixelsPerModule, true); public DrawingImage GetGraphic(int pixelsPerModule, bool drawQuietZones) { @@ -27,9 +25,7 @@ public DrawingImage GetGraphic(int pixelsPerModule, bool drawQuietZones) } public DrawingImage GetGraphic(Size viewBox, bool drawQuietZones = true) - { - return GetGraphic(viewBox, new SolidColorBrush(Colors.Black), new SolidColorBrush(Colors.White), drawQuietZones); - } + => GetGraphic(viewBox, new SolidColorBrush(Colors.Black), new SolidColorBrush(Colors.White), drawQuietZones); public DrawingImage GetGraphic(int pixelsPerModule, string darkColorHex, string lightColorHex, bool drawQuietZones = true) { @@ -69,9 +65,7 @@ public DrawingImage GetGraphic(Size viewBox, Brush darkBrush, Brush lightBrush, } private int GetDrawableModulesCount(bool drawQuietZones = true) - { - return QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8); - } + => QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8); public double GetUnitsPerModule(Size viewBox, bool drawQuietZones = true) { diff --git a/QRCoder/PayloadGenerator/SwissQrCode.cs b/QRCoder/PayloadGenerator/SwissQrCode.cs index bac41ca2..7caf3cb4 100644 --- a/QRCoder/PayloadGenerator/SwissQrCode.cs +++ b/QRCoder/PayloadGenerator/SwissQrCode.cs @@ -389,17 +389,13 @@ public Contact(string name, string country, string addressLine1, string addressL /// Creates a contact with structured address. /// public static Contact WithStructuredAddress(string name, string zipCode, string city, string country, string? street = null, string? houseNumber = null) - { - return new Contact(name, zipCode, city, country, street, houseNumber, AddressType.StructuredAddress); - } + => new Contact(name, zipCode, city, country, street, houseNumber, AddressType.StructuredAddress); /// /// Creates a contact with combined address. /// public static Contact WithCombinedAddress(string name, string country, string addressLine1, string addressLine2) - { - return new Contact(name, null, null, country, addressLine1, addressLine2, AddressType.CombinedAddress); - } + => new Contact(name, null, null, country, addressLine1, addressLine2, AddressType.CombinedAddress); private Contact(string name, string? zipCode, string? city, string country, string? streetOrAddressline1, string? houseNumberOrAddressline2, AddressType addressType) diff --git a/QRCoder/QRCodeGenerator.cs b/QRCoder/QRCodeGenerator.cs index 5f9c3e7e..f446a3f4 100644 --- a/QRCoder/QRCodeGenerator.cs +++ b/QRCoder/QRCodeGenerator.cs @@ -43,9 +43,7 @@ public QRCodeGenerator() /// Thrown when the payload is too big to be encoded in a QR code. /// Returns the raw QR code data which can be used for rendering. public QRCodeData CreateQrCode(PayloadGenerator.Payload payload) - { - return GenerateQrCode(payload); - } + => GenerateQrCode(payload); /// /// Calculates the QR code data which than can be used in one of the rendering classes to generate a graphical representation. @@ -55,9 +53,7 @@ public QRCodeData CreateQrCode(PayloadGenerator.Payload payload) /// Thrown when the payload is too big to be encoded in a QR code. /// Returns the raw QR code data which can be used for rendering. public QRCodeData CreateQrCode(PayloadGenerator.Payload payload, ECCLevel eccLevel) - { - return GenerateQrCode(payload, eccLevel); - } + => GenerateQrCode(payload, eccLevel); /// /// Calculates the QR code data which than can be used in one of the rendering classes to generate a graphical representation. @@ -71,9 +67,7 @@ public QRCodeData CreateQrCode(PayloadGenerator.Payload payload, ECCLevel eccLev /// Thrown when the payload is too big to be encoded in a QR code. /// Returns the raw QR code data which can be used for rendering. public QRCodeData CreateQrCode(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1) - { - return GenerateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion); - } + => GenerateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion); /// /// Calculates the QR code data which than can be used in one of the rendering classes to generate a graphical representation. @@ -83,9 +77,7 @@ public QRCodeData CreateQrCode(string plainText, ECCLevel eccLevel, bool forceUt /// Thrown when the payload is too big to be encoded in a QR code. /// Returns the raw QR code data which can be used for rendering. public QRCodeData CreateQrCode(byte[] binaryData, ECCLevel eccLevel) - { - return GenerateQrCode(binaryData, eccLevel); - } + => GenerateQrCode(binaryData, eccLevel); /// @@ -95,9 +87,7 @@ public QRCodeData CreateQrCode(byte[] binaryData, ECCLevel eccLevel) /// Thrown when the payload is too big to be encoded in a QR code. /// Returns the raw QR code data which can be used for rendering. public static QRCodeData GenerateQrCode(PayloadGenerator.Payload payload) - { - return GenerateQrCode(payload.ToString(), payload.EccLevel, false, false, payload.EciMode, payload.Version); - } + => GenerateQrCode(payload.ToString(), payload.EccLevel, false, false, payload.EciMode, payload.Version); /// /// Calculates the QR code data which than can be used in one of the rendering classes to generate a graphical representation. @@ -635,9 +625,7 @@ private static EncodingMode GetEncodingFromPlaintext(string plainText, bool forc /// Checks if a character falls within a specified range. /// private static bool IsInRange(char c, char min, char max) - { - return (uint)(c - min) <= (uint)(max - min); - } + => (uint)(c - min) <= (uint)(max - min); /// /// Calculates the message polynomial from a bit array which represents the encoded data. @@ -1178,9 +1166,7 @@ int[] GetNotUniqueExponents(Polynom list) /// This is used in Reed-Solomon and other error correction calculations involving Galois fields. /// private static int GetIntValFromAlphaExp(int exp) - { - return _galoisFieldByExponentAlpha[exp]; - } + => _galoisFieldByExponentAlpha[exp]; /// /// Retrieves the exponent from the Galois field that corresponds to a given integer value. @@ -1200,9 +1186,7 @@ private static int GetAlphaExpFromIntVal(int intVal) /// This is particularly necessary when performing multiplications in the field which can result in exponents exceeding the field's maximum. /// private static int ShrinkAlphaExp(int alphaExp) - { - return (int)((alphaExp % 256) + Math.Floor((double)(alphaExp / 256))); - } + => (int)((alphaExp % 256) + Math.Floor((double)(alphaExp / 256))); /// /// Creates a dictionary mapping alphanumeric characters to their respective positions used in QR code encoding. diff --git a/QRCoder/QRCodeGenerator/ModulePlacer.MaskPattern.cs b/QRCoder/QRCodeGenerator/ModulePlacer.MaskPattern.cs index d2da87c2..4b46dac6 100644 --- a/QRCoder/QRCodeGenerator/ModulePlacer.MaskPattern.cs +++ b/QRCoder/QRCodeGenerator/ModulePlacer.MaskPattern.cs @@ -27,72 +27,56 @@ private static class MaskPattern /// Applies a checkerboard mask on the QR code. /// public static bool Pattern1(int x, int y) - { - return (x + y) % 2 == 0; - } + => (x + y) % 2 == 0; /// /// Mask pattern 2: y % 2 == 0 /// Applies a horizontal striping mask on the QR code. /// public static bool Pattern2(int x, int y) - { - return y % 2 == 0; - } + => y % 2 == 0; /// /// Mask pattern 3: x % 3 == 0 /// Applies a vertical striping mask on the QR code. /// public static bool Pattern3(int x, int y) - { - return x % 3 == 0; - } + => x % 3 == 0; /// /// Mask pattern 4: (x + y) % 3 == 0 /// Applies a diagonal striping mask on the QR code. /// public static bool Pattern4(int x, int y) - { - return (x + y) % 3 == 0; - } + => (x + y) % 3 == 0; /// /// Mask pattern 5: ((y / 2) + (x / 3)) % 2 == 0 /// Applies a complex pattern mask on the QR code, mixing horizontal and vertical rules. /// public static bool Pattern5(int x, int y) - { - return ((int)(Math.Floor(y / 2d) + Math.Floor(x / 3d)) % 2) == 0; - } + => ((int)(Math.Floor(y / 2d) + Math.Floor(x / 3d)) % 2) == 0; /// /// Mask pattern 6: ((x * y) % 2 + (x * y) % 3) == 0 /// Applies a mask based on the product of x and y coordinates modulo 2 and 3. /// public static bool Pattern6(int x, int y) - { - return ((x * y) % 2) + ((x * y) % 3) == 0; - } + => ((x * y) % 2) + ((x * y) % 3) == 0; /// /// Mask pattern 7: (((x * y) % 2 + (x * y) % 3) % 2) == 0 /// Applies a mask based on a more complex function involving the product of x and y coordinates. /// public static bool Pattern7(int x, int y) - { - return (((x * y) % 2) + ((x * y) % 3)) % 2 == 0; - } + => (((x * y) % 2) + ((x * y) % 3)) % 2 == 0; /// /// Mask pattern 8: (((x + y) % 2) + ((x * y) % 3) % 2) == 0 /// Combines rules of checkers and complex multiplicative masks. /// public static bool Pattern8(int x, int y) - { - return (((x + y) % 2) + ((x * y) % 3)) % 2 == 0; - } + => (((x + y) % 2) + ((x * y) % 3)) % 2 == 0; /// /// Calculates a penalty score for a QR code to evaluate the effectiveness of a mask pattern. diff --git a/QRCoder/QRCodeGenerator/Polynom.cs b/QRCoder/QRCodeGenerator/Polynom.cs index f93766d3..6fb3c302 100644 --- a/QRCoder/QRCodeGenerator/Polynom.cs +++ b/QRCoder/QRCodeGenerator/Polynom.cs @@ -69,10 +69,7 @@ public PolynomItem this[int index] #if NET6_0_OR_GREATER [StackTraceHidden] #endif - private static void ThrowIndexOutOfRangeException() - { - throw new IndexOutOfRangeException(); - } + private static void ThrowIndexOutOfRangeException() => throw new IndexOutOfRangeException(); /// @@ -83,10 +80,7 @@ private static void ThrowIndexOutOfRangeException() /// /// Removes all polynomial terms from the polynomial. /// - public void Clear() - { - Count = 0; - } + public void Clear() => Count = 0; /// /// Clones the polynomial, creating a new instance with the same polynomial terms. @@ -207,17 +201,13 @@ private void AssertCapacity(int min) /// Rents memory for the polynomial terms from the shared memory pool. /// private static PolynomItem[] RentArray(int count) - { - return System.Buffers.ArrayPool.Shared.Rent(count); - } + => System.Buffers.ArrayPool.Shared.Rent(count); /// /// Returns memory allocated for the polynomial terms back to the shared memory pool. /// private static void ReturnArray(PolynomItem[] array) - { - System.Buffers.ArrayPool.Shared.Return(array); - } + => System.Buffers.ArrayPool.Shared.Return(array); #else // Implement a poor-man's array pool for .NET Framework [ThreadStatic] diff --git a/QRCoderDemoUWP/App.xaml.cs b/QRCoderDemoUWP/App.xaml.cs index 5188504d..91a29799 100644 --- a/QRCoderDemoUWP/App.xaml.cs +++ b/QRCoderDemoUWP/App.xaml.cs @@ -20,7 +20,7 @@ namespace QRCoderDemoUWP; /// /// Provides application-specific behavior to supplement the default Application class. /// -internal sealed partial class App : Application +public sealed partial class App : Application { /// /// Initializes the singleton application object. This is the first line of authored code diff --git a/QRCoderTests/Helpers/HelperFunctions.cs b/QRCoderTests/Helpers/HelperFunctions.cs index aa07dc70..19e6fe93 100644 --- a/QRCoderTests/Helpers/HelperFunctions.cs +++ b/QRCoderTests/Helpers/HelperFunctions.cs @@ -103,7 +103,5 @@ public static string ByteArrayToHash(byte[] data) } public static string StringToHash(string data) - { - return ByteArrayToHash(Encoding.UTF8.GetBytes(data)); - } + => ByteArrayToHash(Encoding.UTF8.GetBytes(data)); }