Skip to content

Commit d2e7528

Browse files
authored
Merge pull request #211 from barnhill/cleanup_lint_warnings
Address project wide lint warnings, remove useless comments, remove broken reference
2 parents 6ed8ac9 + 93b554f commit d2e7528

29 files changed

+505
-776
lines changed

BarcodeStandard/BarcodeCommon.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace BarcodeStandard
66
internal abstract class BarcodeCommon
77
{
88
public string RawData { get; protected set; } = "";
9-
public List<string> Errors { get; } = new List<string>();
9+
public List<string> Errors { get; } = [];
1010

1111
protected void Error(string errorMessage)
1212
{
@@ -27,16 +27,12 @@ internal static bool IsNumericOnly(string s)
2727

2828
internal static int GetAlignmentShiftAdjustment(Barcode barcode)
2929
{
30-
switch (barcode.Alignment)
30+
return barcode.Alignment switch
3131
{
32-
case AlignmentPositions.Left:
33-
return 0;
34-
case AlignmentPositions.Right:
35-
return (barcode.Width % barcode.EncodedValue.Length);
36-
case AlignmentPositions.Center:
37-
default:
38-
return (barcode.Width % barcode.EncodedValue.Length) / 2;
39-
}//switch
32+
AlignmentPositions.Left => 0,
33+
AlignmentPositions.Right => (barcode.Width % barcode.EncodedValue.Length),
34+
_ => (barcode.Width % barcode.EncodedValue.Length) / 2,
35+
};
4036
}
4137
}//BarcodeVariables abstract class
42-
}//namespace
38+
}

BarcodeStandard/BarcodeLib.cs

Lines changed: 175 additions & 269 deletions
Large diffs are not rendered by default.

BarcodeStandard/BarcodeStandard.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
5-
<Version>3.1.3</Version>
5+
<Version>3.1.4</Version>
66
<PackageId>BarcodeLib</PackageId>
77
<Company>Pnuema Productions</Company>
88
<Product>BarcodeLib</Product>
@@ -18,8 +18,8 @@
1818
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
1919
<PackageIcon>upca.jpg</PackageIcon>
2020
<PackageIconUrl />
21-
<AssemblyVersion>3.1.3.0</AssemblyVersion>
22-
<FileVersion>3.1.3.0</FileVersion>
21+
<AssemblyVersion>3.1.4.0</AssemblyVersion>
22+
<FileVersion>3.1.4.0</FileVersion>
2323
<TargetFramework>netstandard2.0</TargetFramework>
2424
<LangVersion>latest</LangVersion>
2525
<SignAssembly>true</SignAssembly>
@@ -28,14 +28,14 @@
2828
</PropertyGroup>
2929

3030
<ItemGroup>
31-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
31+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
3232
</ItemGroup>
3333

3434
<ItemGroup>
35-
<PackageReference Include="SkiaSharp" Version="2.88.6" />
36-
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
37-
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" />
38-
<PackageReference Include="System.Text.Json" Version="7.0.3" />
35+
<PackageReference Include="SkiaSharp" Version="2.88.8" />
36+
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
37+
<PackageReference Include="System.Resources.Extensions" Version="8.0.0" />
38+
<PackageReference Include="System.Text.Json" Version="8.0.4" />
3939
</ItemGroup>
4040

4141
<ItemGroup>

BarcodeStandard/IBarcode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ List<string> Errors
2424
}//Errors
2525

2626
}//interface
27-
}//namespace
27+
}

BarcodeStandard/Labels.cs

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,51 @@ public static SKImage Label_ITF14(Barcode barcode, SKBitmap img)
2626
var labelPadding = textBounds.Height / 2f;
2727
var backY = img.Height - textBounds.Height - labelPadding * 2f;
2828

29-
using (var canvas = new SKCanvas(img))
29+
using var canvas = new SKCanvas(img);
30+
//draw bounding box side overdrawn by label
31+
using (var pen = new SKPaint())
3032
{
31-
//draw bounding box side overdrawn by label
32-
using (var pen = new SKPaint())
33-
{
34-
pen.FilterQuality = SKFilterQuality.High;
35-
pen.IsAntialias = true;
36-
pen.ColorF = barcode.ForeColor;
37-
pen.StrokeWidth = (float)img.Height / 16;
38-
39-
canvas.DrawLine(new SKPoint(0, backY - pen.StrokeWidth / 2f),
40-
new SKPoint(img.Width, backY - pen.StrokeWidth / 2f), pen); //bottom
41-
}
42-
43-
//color a box at the bottom of the barcode to hold the string of data
44-
using (var paint = new SKPaint(font))
45-
{
46-
paint.FilterQuality = SKFilterQuality.High;
47-
paint.IsAntialias = true;
48-
paint.ColorF = barcode.BackColor;
49-
paint.Style = SKPaintStyle.Fill;
50-
51-
var rect = SKRect.Create(0, backY, img.Width, textBounds.Height + labelPadding * 2f);
52-
canvas.DrawRect(rect, paint);
53-
}
54-
55-
//draw datastring under the barcode image
56-
foreBrush.FilterQuality = SKFilterQuality.High;
57-
foreBrush.IsAntialias = true;
58-
foreBrush.ColorF = barcode.ForeColor;
59-
foreBrush.TextAlign = SKTextAlign.Center;
60-
61-
var labelX = img.Width / 2f;
62-
var labelY = img.Height - textBounds.Height + labelPadding;
63-
64-
canvas.DrawText(str, labelX, labelY, foreBrush);
65-
66-
canvas.Save();
67-
} //using
33+
pen.FilterQuality = SKFilterQuality.High;
34+
pen.IsAntialias = true;
35+
pen.ColorF = barcode.ForeColor;
36+
pen.StrokeWidth = (float)img.Height / 16;
37+
38+
canvas.DrawLine(new SKPoint(0, backY - pen.StrokeWidth / 2f),
39+
new SKPoint(img.Width, backY - pen.StrokeWidth / 2f), pen); //bottom
40+
}
41+
42+
//color a box at the bottom of the barcode to hold the string of data
43+
using (var paint = new SKPaint(font))
44+
{
45+
paint.FilterQuality = SKFilterQuality.High;
46+
paint.IsAntialias = true;
47+
paint.ColorF = barcode.BackColor;
48+
paint.Style = SKPaintStyle.Fill;
49+
50+
var rect = SKRect.Create(0, backY, img.Width, textBounds.Height + labelPadding * 2f);
51+
canvas.DrawRect(rect, paint);
52+
}
53+
54+
//draw datastring under the barcode image
55+
foreBrush.FilterQuality = SKFilterQuality.High;
56+
foreBrush.IsAntialias = true;
57+
foreBrush.ColorF = barcode.ForeColor;
58+
foreBrush.TextAlign = SKTextAlign.Center;
59+
60+
var labelX = img.Width / 2f;
61+
var labelY = img.Height - textBounds.Height + labelPadding;
62+
63+
canvas.DrawText(str, labelX, labelY, foreBrush);
64+
65+
canvas.Save();
6866
}
6967

7068
return SKImage.FromBitmap(img);
71-
}//try
69+
}
7270
catch (Exception ex)
7371
{
7472
throw new Exception("ELABEL_ITF14-1: " + ex.Message);
75-
}//catch
73+
}
7674
}
7775

7876
/// <summary>
@@ -128,11 +126,11 @@ public static SKImage Label_Generic(Barcode barcode, SKBitmap img)
128126
g.Save();
129127
}
130128
return SKImage.FromBitmap(img);
131-
}//try
129+
}
132130
catch (Exception ex)
133131
{
134132
throw new Exception("ELABEL_GENERIC-1: " + ex.Message);
135-
}//catch
133+
}
136134
finally
137135
{
138136
foreBrush.Dispose();
@@ -220,11 +218,11 @@ public static SKImage Label_EAN13(Barcode barcode, SKBitmap img)
220218
}
221219

222220
return SKImage.FromBitmap(img);
223-
}//try
221+
}
224222
catch (Exception ex)
225223
{
226224
throw new Exception("ELABEL_EAN13-1: " + ex.Message);
227-
}//catch
225+
}
228226
finally
229227
{
230228
foreBrush.Dispose();
@@ -316,19 +314,19 @@ public static SKImage Label_UPCA(Barcode barcode, SKBitmap img)
316314
}
317315

318316
return SKImage.FromBitmap(img);
319-
}//try
317+
}
320318
catch (Exception ex)
321319
{
322320
throw new Exception("ELABEL_UPCA-1: " + ex.Message);
323-
}//catch
321+
}
324322
finally
325323
{
326324
foreBrush.Dispose();
327325
backBrush.Dispose();
328326
}
329327
}//Label_UPCA
330328

331-
private static int GetFontSize(Barcode barcode, int wid, int hgt, string lbl)
329+
/*private static int GetFontSize(int wid, int hgt, string lbl)
332330
{
333331
//Returns the optimal font size for the specified dimensions
334332
var fontSize = 10;
@@ -338,23 +336,19 @@ private static int GetFontSize(Barcode barcode, int wid, int hgt, string lbl)
338336
var bounds = SKRect.Empty;
339337
for (var i = 1; i <= 100; i++)
340338
{
341-
using (var testFont = new SKFont(SKTypeface.FromFamilyName("Arial", SKFontStyle.Normal), i))
342-
{
343-
// Make a Graphics object to measure the text.
344-
using (var gr = new SKPaint(testFont))
345-
{
346-
gr.MeasureText(lbl, ref bounds);
347-
348-
if (!(bounds.Width > wid) && !(bounds.Height > hgt)) continue;
349-
fontSize = i - 1;
350-
break;
351-
}
352-
}
339+
using var testFont = new SKFont(SKTypeface.FromFamilyName("Arial", SKFontStyle.Normal), i);
340+
// Make a Graphics object to measure the text.
341+
using var gr = new SKPaint(testFont);
342+
gr.MeasureText(lbl, ref bounds);
343+
344+
if (!(bounds.Width > wid) && !(bounds.Height > hgt)) continue;
345+
fontSize = i - 1;
346+
break;
353347
}
354348
355349
};
356350
357351
return fontSize;
358-
}
352+
}*/
359353
}
360354
}

BarcodeStandard/Symbologies/Codabar.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace BarcodeStandard.Symbologies
66
/// </summary>
77
internal class Codabar : BarcodeCommon, IBarcode
88
{
9-
private readonly System.Collections.Hashtable Codabar_Code = new System.Collections.Hashtable(); //is initialized by init_Codabar()
9+
private readonly System.Collections.Hashtable Codabar_Code = []; //is initialized by init_Codabar()
1010

1111
internal Codabar(string input)
1212
{
1313
RawData = input;
14-
}//Codabar
14+
}
1515

1616
/// <summary>
1717
/// Encode the raw data using the Codabar algorithm.
@@ -29,7 +29,7 @@ private string Encode_Codabar()
2929
case "D": break;
3030
default: Error("ECODABAR-2: Data format invalid. (Invalid START character)");
3131
break;
32-
}//switch
32+
}
3333

3434
//check the ending char to make sure its a start/stop char
3535
switch (RawData[RawData.Trim().Length - 1].ToString().ToUpper().Trim())
@@ -40,10 +40,10 @@ private string Encode_Codabar()
4040
case "D": break;
4141
default: Error("ECODABAR-3: Data format invalid. (Invalid STOP character)");
4242
break;
43-
}//switch
43+
}
4444

4545
//populate the hashtable to begin the process
46-
init_Codabar();
46+
Init_Codabar();
4747

4848
//replace non-numeric VALID chars with empty strings before checking for all numerics
4949
var temp = RawData;
@@ -53,8 +53,8 @@ private string Encode_Codabar()
5353
if (!IsNumericOnly(c.ToString()))
5454
{
5555
temp = temp.Replace(c, '1');
56-
}//if
57-
}//if
56+
}
57+
}
5858

5959
//now that all the valid non-numeric chars have been replaced with a number check if all numeric exist
6060
if (!IsNumericOnly(temp))
@@ -66,7 +66,7 @@ private string Encode_Codabar()
6666
{
6767
result += Codabar_Code[c].ToString();
6868
result += "0"; //inter-character space
69-
}//foreach
69+
}
7070

7171
//remove the extra 0 at the end of the result
7272
result = result.Remove(result.Length - 1);
@@ -78,8 +78,8 @@ private string Encode_Codabar()
7878
RawData = RawData.Trim().Substring(1, RawData.Trim().Length - 2);
7979

8080
return result;
81-
}//Encode_Codabar
82-
private void init_Codabar()
81+
}
82+
private void Init_Codabar()
8383
{
8484
Codabar_Code.Clear();
8585
Codabar_Code.Add('0', "101010011");
@@ -106,13 +106,13 @@ private void init_Codabar()
106106
Codabar_Code.Add('b', "1010010011");
107107
Codabar_Code.Add('c', "1001001011");
108108
Codabar_Code.Add('d', "1010011001");
109-
}//init_Codeabar
109+
}
110110

111111
#region IBarcode Members
112112

113113
public string Encoded_Value => Encode_Codabar();
114114

115115
#endregion
116116

117-
}//class
118-
}//namespace
117+
}
118+
}

BarcodeStandard/Symbologies/Code11.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ namespace BarcodeStandard.Symbologies
88
/// </summary>
99
internal class Code11 : BarcodeCommon, IBarcode
1010
{
11-
private readonly string[] C11_Code = { "101011", "1101011", "1001011", "1100101", "1011011", "1101101", "1001101", "1010011", "1101001", "110101", "101101", "1011001" };
11+
private readonly string[] C11_Code = ["101011", "1101011", "1001011", "1100101", "1011011", "1101101", "1001101", "1010011", "1101001", "110101", "101101", "1011001"];
1212

1313
internal Code11(string input)
1414
{
1515
RawData = input;
16-
}//Code11
16+
}
1717
/// <summary>
1818
/// Encode the raw data using the Code 11 algorithm.
1919
/// </summary>
@@ -37,7 +37,7 @@ private string Encode_Code11()
3737
cTotal += Int32.Parse(RawData[i].ToString()) * weight++;
3838
else
3939
cTotal += 10 * weight++;
40-
}//for
40+
}
4141
var checksumC = cTotal % 11;
4242

4343
dataToEncodeWithChecksums += checksumC.ToString();
@@ -58,10 +58,10 @@ private string Encode_Code11()
5858
kTotal += Int32.Parse(dataToEncodeWithChecksums[i].ToString()) * weight++;
5959
else
6060
kTotal += 10 * weight++;
61-
}//for
61+
}
6262
var checksumK = kTotal % 11;
6363
dataToEncodeWithChecksums += checksumK.ToString();
64-
}//if
64+
}
6565

6666
//encode data
6767
var space = "0";
@@ -74,18 +74,18 @@ private string Encode_Code11()
7474

7575
//inter-character space
7676
result += space;
77-
}//foreach
77+
}
7878

7979
//stop bars
8080
result += C11_Code[11];
8181

8282
return result;
83-
}//Encode_Code11
83+
}
8484

8585
#region IBarcode Members
8686

8787
public string Encoded_Value => Encode_Code11();
8888

8989
#endregion
90-
}//class
91-
}//namespace
90+
}
91+
}

0 commit comments

Comments
 (0)