Skip to content

Commit 7698bf3

Browse files
committed
Use expression body for method
1 parent d66816d commit 7698bf3

File tree

8 files changed

+28
-81
lines changed

8 files changed

+28
-81
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,4 @@ dotnet_diagnostic.IDE0005.severity = warning
263263
# Enforce formatting https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#rule-id-ide0055-fix-formatting
264264
dotnet_diagnostic.IDE0055.severity = error
265265
dotnet_diagnostic.IDE1006.severity = error
266+
dotnet_diagnostic.IDE0022.severity = error

QRCoder.Xaml/XamlQRCode.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ public XamlQRCode() { }
1515
public XamlQRCode(QRCodeData data) : base(data) { }
1616

1717
public DrawingImage GetGraphic(int pixelsPerModule)
18-
{
19-
return GetGraphic(pixelsPerModule, true);
20-
}
18+
=> GetGraphic(pixelsPerModule, true);
2119

2220
public DrawingImage GetGraphic(int pixelsPerModule, bool drawQuietZones)
2321
{
@@ -27,9 +25,7 @@ public DrawingImage GetGraphic(int pixelsPerModule, bool drawQuietZones)
2725
}
2826

2927
public DrawingImage GetGraphic(Size viewBox, bool drawQuietZones = true)
30-
{
31-
return GetGraphic(viewBox, new SolidColorBrush(Colors.Black), new SolidColorBrush(Colors.White), drawQuietZones);
32-
}
28+
=> GetGraphic(viewBox, new SolidColorBrush(Colors.Black), new SolidColorBrush(Colors.White), drawQuietZones);
3329

3430
public DrawingImage GetGraphic(int pixelsPerModule, string darkColorHex, string lightColorHex, bool drawQuietZones = true)
3531
{
@@ -69,9 +65,7 @@ public DrawingImage GetGraphic(Size viewBox, Brush darkBrush, Brush lightBrush,
6965
}
7066

7167
private int GetDrawableModulesCount(bool drawQuietZones = true)
72-
{
73-
return QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8);
74-
}
68+
=> QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8);
7569

7670
public double GetUnitsPerModule(Size viewBox, bool drawQuietZones = true)
7771
{

QRCoder/PayloadGenerator/SwissQrCode.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,17 +389,13 @@ public Contact(string name, string country, string addressLine1, string addressL
389389
/// Creates a contact with structured address.
390390
/// </summary>
391391
public static Contact WithStructuredAddress(string name, string zipCode, string city, string country, string? street = null, string? houseNumber = null)
392-
{
393-
return new Contact(name, zipCode, city, country, street, houseNumber, AddressType.StructuredAddress);
394-
}
392+
=> new Contact(name, zipCode, city, country, street, houseNumber, AddressType.StructuredAddress);
395393

396394
/// <summary>
397395
/// Creates a contact with combined address.
398396
/// </summary>
399397
public static Contact WithCombinedAddress(string name, string country, string addressLine1, string addressLine2)
400-
{
401-
return new Contact(name, null, null, country, addressLine1, addressLine2, AddressType.CombinedAddress);
402-
}
398+
=> new Contact(name, null, null, country, addressLine1, addressLine2, AddressType.CombinedAddress);
403399

404400

405401
private Contact(string name, string? zipCode, string? city, string country, string? streetOrAddressline1, string? houseNumberOrAddressline2, AddressType addressType)

QRCoder/QRCodeGenerator.cs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public QRCodeGenerator()
4343
/// <exception cref="QRCoder.Exceptions.DataTooLongException">Thrown when the payload is too big to be encoded in a QR code.</exception>
4444
/// <returns>Returns the raw QR code data which can be used for rendering.</returns>
4545
public QRCodeData CreateQrCode(PayloadGenerator.Payload payload)
46-
{
47-
return GenerateQrCode(payload);
48-
}
46+
=> GenerateQrCode(payload);
4947

5048
/// <summary>
5149
/// 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)
5553
/// <exception cref="QRCoder.Exceptions.DataTooLongException">Thrown when the payload is too big to be encoded in a QR code.</exception>
5654
/// <returns>Returns the raw QR code data which can be used for rendering.</returns>
5755
public QRCodeData CreateQrCode(PayloadGenerator.Payload payload, ECCLevel eccLevel)
58-
{
59-
return GenerateQrCode(payload, eccLevel);
60-
}
56+
=> GenerateQrCode(payload, eccLevel);
6157

6258
/// <summary>
6359
/// 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
7167
/// <exception cref="QRCoder.Exceptions.DataTooLongException">Thrown when the payload is too big to be encoded in a QR code.</exception>
7268
/// <returns>Returns the raw QR code data which can be used for rendering.</returns>
7369
public QRCodeData CreateQrCode(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1)
74-
{
75-
return GenerateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion);
76-
}
70+
=> GenerateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion);
7771

7872
/// <summary>
7973
/// 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
8377
/// <exception cref="QRCoder.Exceptions.DataTooLongException">Thrown when the payload is too big to be encoded in a QR code.</exception>
8478
/// <returns>Returns the raw QR code data which can be used for rendering.</returns>
8579
public QRCodeData CreateQrCode(byte[] binaryData, ECCLevel eccLevel)
86-
{
87-
return GenerateQrCode(binaryData, eccLevel);
88-
}
80+
=> GenerateQrCode(binaryData, eccLevel);
8981

9082

9183
/// <summary>
@@ -95,9 +87,7 @@ public QRCodeData CreateQrCode(byte[] binaryData, ECCLevel eccLevel)
9587
/// <exception cref="QRCoder.Exceptions.DataTooLongException">Thrown when the payload is too big to be encoded in a QR code.</exception>
9688
/// <returns>Returns the raw QR code data which can be used for rendering.</returns>
9789
public static QRCodeData GenerateQrCode(PayloadGenerator.Payload payload)
98-
{
99-
return GenerateQrCode(payload.ToString(), payload.EccLevel, false, false, payload.EciMode, payload.Version);
100-
}
90+
=> GenerateQrCode(payload.ToString(), payload.EccLevel, false, false, payload.EciMode, payload.Version);
10191

10292
/// <summary>
10393
/// 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
635625
/// Checks if a character falls within a specified range.
636626
/// </summary>
637627
private static bool IsInRange(char c, char min, char max)
638-
{
639-
return (uint)(c - min) <= (uint)(max - min);
640-
}
628+
=> (uint)(c - min) <= (uint)(max - min);
641629

642630
/// <summary>
643631
/// Calculates the message polynomial from a bit array which represents the encoded data.
@@ -1178,9 +1166,7 @@ int[] GetNotUniqueExponents(Polynom list)
11781166
/// This is used in Reed-Solomon and other error correction calculations involving Galois fields.
11791167
/// </summary>
11801168
private static int GetIntValFromAlphaExp(int exp)
1181-
{
1182-
return _galoisFieldByExponentAlpha[exp];
1183-
}
1169+
=> _galoisFieldByExponentAlpha[exp];
11841170

11851171
/// <summary>
11861172
/// Retrieves the exponent from the Galois field that corresponds to a given integer value.
@@ -1200,9 +1186,7 @@ private static int GetAlphaExpFromIntVal(int intVal)
12001186
/// This is particularly necessary when performing multiplications in the field which can result in exponents exceeding the field's maximum.
12011187
/// </summary>
12021188
private static int ShrinkAlphaExp(int alphaExp)
1203-
{
1204-
return (int)((alphaExp % 256) + Math.Floor((double)(alphaExp / 256)));
1205-
}
1189+
=> (int)((alphaExp % 256) + Math.Floor((double)(alphaExp / 256)));
12061190

12071191
/// <summary>
12081192
/// Creates a dictionary mapping alphanumeric characters to their respective positions used in QR code encoding.

QRCoder/QRCodeGenerator/ModulePlacer.MaskPattern.cs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,72 +27,56 @@ private static class MaskPattern
2727
/// Applies a checkerboard mask on the QR code.
2828
/// </summary>
2929
public static bool Pattern1(int x, int y)
30-
{
31-
return (x + y) % 2 == 0;
32-
}
30+
=> (x + y) % 2 == 0;
3331

3432
/// <summary>
3533
/// Mask pattern 2: y % 2 == 0
3634
/// Applies a horizontal striping mask on the QR code.
3735
/// </summary>
3836
public static bool Pattern2(int x, int y)
39-
{
40-
return y % 2 == 0;
41-
}
37+
=> y % 2 == 0;
4238

4339
/// <summary>
4440
/// Mask pattern 3: x % 3 == 0
4541
/// Applies a vertical striping mask on the QR code.
4642
/// </summary>
4743
public static bool Pattern3(int x, int y)
48-
{
49-
return x % 3 == 0;
50-
}
44+
=> x % 3 == 0;
5145

5246
/// <summary>
5347
/// Mask pattern 4: (x + y) % 3 == 0
5448
/// Applies a diagonal striping mask on the QR code.
5549
/// </summary>
5650
public static bool Pattern4(int x, int y)
57-
{
58-
return (x + y) % 3 == 0;
59-
}
51+
=> (x + y) % 3 == 0;
6052

6153
/// <summary>
6254
/// Mask pattern 5: ((y / 2) + (x / 3)) % 2 == 0
6355
/// Applies a complex pattern mask on the QR code, mixing horizontal and vertical rules.
6456
/// </summary>
6557
public static bool Pattern5(int x, int y)
66-
{
67-
return ((int)(Math.Floor(y / 2d) + Math.Floor(x / 3d)) % 2) == 0;
68-
}
58+
=> ((int)(Math.Floor(y / 2d) + Math.Floor(x / 3d)) % 2) == 0;
6959

7060
/// <summary>
7161
/// Mask pattern 6: ((x * y) % 2 + (x * y) % 3) == 0
7262
/// Applies a mask based on the product of x and y coordinates modulo 2 and 3.
7363
/// </summary>
7464
public static bool Pattern6(int x, int y)
75-
{
76-
return ((x * y) % 2) + ((x * y) % 3) == 0;
77-
}
65+
=> ((x * y) % 2) + ((x * y) % 3) == 0;
7866

7967
/// <summary>
8068
/// Mask pattern 7: (((x * y) % 2 + (x * y) % 3) % 2) == 0
8169
/// Applies a mask based on a more complex function involving the product of x and y coordinates.
8270
/// </summary>
8371
public static bool Pattern7(int x, int y)
84-
{
85-
return (((x * y) % 2) + ((x * y) % 3)) % 2 == 0;
86-
}
72+
=> (((x * y) % 2) + ((x * y) % 3)) % 2 == 0;
8773

8874
/// <summary>
8975
/// Mask pattern 8: (((x + y) % 2) + ((x * y) % 3) % 2) == 0
9076
/// Combines rules of checkers and complex multiplicative masks.
9177
/// </summary>
9278
public static bool Pattern8(int x, int y)
93-
{
94-
return (((x + y) % 2) + ((x * y) % 3)) % 2 == 0;
95-
}
79+
=> (((x + y) % 2) + ((x * y) % 3)) % 2 == 0;
9680

9781
/// <summary>
9882
/// Calculates a penalty score for a QR code to evaluate the effectiveness of a mask pattern.

QRCoder/QRCodeGenerator/Polynom.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ public PolynomItem this[int index]
6969
#if NET6_0_OR_GREATER
7070
[StackTraceHidden]
7171
#endif
72-
private static void ThrowIndexOutOfRangeException()
73-
{
74-
throw new IndexOutOfRangeException();
75-
}
72+
private static void ThrowIndexOutOfRangeException() => throw new IndexOutOfRangeException();
7673

7774

7875
/// <summary>
@@ -83,10 +80,7 @@ private static void ThrowIndexOutOfRangeException()
8380
/// <summary>
8481
/// Removes all polynomial terms from the polynomial.
8582
/// </summary>
86-
public void Clear()
87-
{
88-
Count = 0;
89-
}
83+
public void Clear() => Count = 0;
9084

9185
/// <summary>
9286
/// Clones the polynomial, creating a new instance with the same polynomial terms.
@@ -207,17 +201,13 @@ private void AssertCapacity(int min)
207201
/// Rents memory for the polynomial terms from the shared memory pool.
208202
/// </summary>
209203
private static PolynomItem[] RentArray(int count)
210-
{
211-
return System.Buffers.ArrayPool<PolynomItem>.Shared.Rent(count);
212-
}
204+
=> System.Buffers.ArrayPool<PolynomItem>.Shared.Rent(count);
213205

214206
/// <summary>
215207
/// Returns memory allocated for the polynomial terms back to the shared memory pool.
216208
/// </summary>
217209
private static void ReturnArray(PolynomItem[] array)
218-
{
219-
System.Buffers.ArrayPool<PolynomItem>.Shared.Return(array);
220-
}
210+
=> System.Buffers.ArrayPool<PolynomItem>.Shared.Return(array);
221211
#else
222212
// Implement a poor-man's array pool for .NET Framework
223213
[ThreadStatic]

QRCoderDemoUWP/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace QRCoderDemoUWP;
2020
/// <summary>
2121
/// Provides application-specific behavior to supplement the default Application class.
2222
/// </summary>
23-
internal sealed partial class App : Application
23+
public sealed partial class App : Application
2424
{
2525
/// <summary>
2626
/// Initializes the singleton application object. This is the first line of authored code

QRCoderTests/Helpers/HelperFunctions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,5 @@ public static string ByteArrayToHash(byte[] data)
103103
}
104104

105105
public static string StringToHash(string data)
106-
{
107-
return ByteArrayToHash(Encoding.UTF8.GetBytes(data));
108-
}
106+
=> ByteArrayToHash(Encoding.UTF8.GetBytes(data));
109107
}

0 commit comments

Comments
 (0)