Skip to content

Commit 25ddf0a

Browse files
committed
Enhance project configuration and update dependencies
- Updated `.editorconfig` with new C# style rules and naming conventions. - Modified `copilot-instructions.md` and `README.md` for .NET 10.0 support and SkiaSharp upgrade to 3.119.0. - Upgraded BenchmarkDotNet to version 0.15.2 in benchmark projects. - Refactored `BarcodeOptionsTest.cs` for improved readability with modern C# syntax. - Added new dependencies, including PolySharp, and updated existing packages. - Improved encoder classes with modern C# features and enhanced exception handling. - Incremented version number in `TyKonKet.BarcodeGenerator.csproj` to 2.1.0.
1 parent 212a212 commit 25ddf0a

File tree

20 files changed

+251
-199
lines changed

20 files changed

+251
-199
lines changed

.editorconfig

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,96 @@ dotnet_analyzer_diagnostic.category-StyleCop.CSharp.OrderingRules.severity = non
88

99
# Wintellect004: Use explicit types instead of predefined to avoid confusion
1010
dotnet_diagnostic.Wintellect004.severity = none
11+
csharp_using_directive_placement = outside_namespace:silent
12+
csharp_prefer_simple_using_statement = true:suggestion
13+
csharp_prefer_braces = true:silent
14+
csharp_style_namespace_declarations = block_scoped:silent
15+
csharp_style_prefer_method_group_conversion = true:silent
16+
csharp_style_prefer_top_level_statements = true:silent
17+
csharp_style_prefer_primary_constructors = true:suggestion
18+
csharp_prefer_system_threading_lock = true:suggestion
19+
csharp_style_expression_bodied_methods = false:silent
20+
csharp_style_expression_bodied_constructors = false:silent
21+
csharp_style_expression_bodied_operators = false:silent
22+
csharp_style_expression_bodied_properties = true:silent
23+
csharp_style_expression_bodied_indexers = true:silent
24+
csharp_style_expression_bodied_accessors = true:silent
25+
csharp_style_expression_bodied_lambdas = true:silent
26+
csharp_style_expression_bodied_local_functions = false:silent
27+
csharp_style_throw_expression = true:suggestion
28+
csharp_style_prefer_null_check_over_type_check = true:suggestion
29+
csharp_prefer_simple_default_expression = true:suggestion
30+
csharp_indent_labels = one_less_than_current
31+
csharp_style_prefer_local_over_anonymous_function = true:suggestion
32+
dotnet_diagnostic.SA1009.severity = none
33+
dotnet_diagnostic.SA1010.severity = none
34+
dotnet_diagnostic.SA1000.severity = none
35+
dotnet_diagnostic.SA1128.severity = none
36+
37+
[*.{cs,vb}]
38+
#### Naming styles ####
39+
40+
# Naming rules
41+
42+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
43+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
44+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
45+
46+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
47+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
48+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
49+
50+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
51+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
52+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
53+
54+
# Symbol specifications
55+
56+
dotnet_naming_symbols.interface.applicable_kinds = interface
57+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
58+
dotnet_naming_symbols.interface.required_modifiers =
59+
60+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
61+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
62+
dotnet_naming_symbols.types.required_modifiers =
63+
64+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
65+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
66+
dotnet_naming_symbols.non_field_members.required_modifiers =
67+
68+
# Naming styles
69+
70+
dotnet_naming_style.begins_with_i.required_prefix = I
71+
dotnet_naming_style.begins_with_i.required_suffix =
72+
dotnet_naming_style.begins_with_i.word_separator =
73+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
74+
75+
dotnet_naming_style.pascal_case.required_prefix =
76+
dotnet_naming_style.pascal_case.required_suffix =
77+
dotnet_naming_style.pascal_case.word_separator =
78+
dotnet_naming_style.pascal_case.capitalization = pascal_case
79+
80+
dotnet_naming_style.pascal_case.required_prefix =
81+
dotnet_naming_style.pascal_case.required_suffix =
82+
dotnet_naming_style.pascal_case.word_separator =
83+
dotnet_naming_style.pascal_case.capitalization = pascal_case
84+
dotnet_style_coalesce_expression = true:suggestion
85+
dotnet_style_null_propagation = true:suggestion
86+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
87+
dotnet_style_prefer_auto_properties = true:silent
88+
dotnet_style_object_initializer = true:suggestion
89+
dotnet_style_collection_initializer = true:suggestion
90+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
91+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
92+
dotnet_style_prefer_conditional_expression_over_return = true:silent
93+
dotnet_style_explicit_tuple_names = true:suggestion
94+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
95+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
96+
dotnet_style_prefer_compound_assignment = true:suggestion
97+
dotnet_style_prefer_simplified_interpolation = true:suggestion
98+
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
99+
dotnet_style_namespace_match_folder = true:suggestion
100+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
101+
tab_width = 4
102+
indent_size = 4
103+
end_of_line = crlf

.github/copilot-instructions.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
**Repository Size**: Medium (~50 source files)
88
**Project Type**: .NET Class Library
9-
**Languages**: C# (.NET Standard 2.0, .NET 6.0, .NET 8.0, .NET Framework 4.6.2)
10-
**Main Dependencies**: SkiaSharp 3.116.1, System.ValueTuple
9+
**Languages**: C# (.NET Standard 2.0, .NET 6.0, .NET 8.0, .NET 10.0, .NET Framework 4.6.2)
10+
**Main Dependencies**: SkiaSharp 3.119.0, System.ValueTuple, PolySharp 1.15.0, System.Memory 4.5.5, System.Threading.Tasks.Extensions 4.5.4, System.Buffers 4.5.1
1111
**Test Framework**: xUnit with BenchmarkDotNet for performance testing
1212

1313
## Build Instructions
@@ -147,19 +147,19 @@ barcode.Export("path/{barcode}.png", SKEncodedImageFormat.Png, 100);
147147

148148
### Framework Targeting
149149
- **.NET Standard 2.0**: Core compatibility target
150-
- **.NET Framework 4.6.2**: Legacy Windows support
150+
- **.NET Framework 4.6.2**: Legacy Windows support
151151
- **.NET 6.0**: LTS version support
152152
- **.NET 8.0**: Current stable version
153+
- **.NET 10.0**: Future-ready version
153154

154155
### Runtime Dependencies
155-
- **SkiaSharp 3.116.1**: Cross-platform 2D graphics (core dependency)
156-
- **SkiaSharp.NativeAssets.Linux.NoDependencies**: Linux native support
157-
- **System.ValueTuple 4.5.0**: Compatibility for older frameworks
158-
159-
### Breaking Changes (v2.0.0+)
160-
- No longer supports .NET Standard 1.3 (requires 2.0+)
161-
- API redesigned for better usability and customization
162-
- SkiaSharp updated to 3.116.1
156+
- **SkiaSharp 3.119.0**: Cross-platform 2D graphics (core dependency)
157+
- **SkiaSharp.NativeAssets.Linux.NoDependencies 3.119.0**: Linux native support
158+
- **System.ValueTuple 4.6.1**: Compatibility for older frameworks
159+
- **System.Memory 4.5.5**: Memory management utilities for older frameworks
160+
- **System.Threading.Tasks.Extensions 4.5.4**: Task-based asynchronous programming for older frameworks
161+
- **System.Buffers 4.5.1**: Provides array pool and memory management utilities
162+
- **PolySharp 1.15.0**: Enhances compatibility with older runtimes
163163

164164
## Testing Guidelines
165165

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Designed for performance, flexibility, and ease of use across all .NET platforms
4444
- 🔧 **Action Delegate Configuration** - Intuitive configuration with lambda expressions
4545
- 📸 **Multiple Export Formats** - PNG, JPEG, and other image formats
4646
-**Validation** - Automatic check digit calculation and validation
47-
- 🔌 **Framework Support** - .NET Standard 2.0, .NET Framework 4.6.2, .NET 6.0, .NET 8.0
47+
- 🔌 **Framework Support** - .NET Standard 2.0, .NET Framework 4.6.2, .NET 6.0, .NET 8.0, .NET 10.0
4848

4949
---
5050

@@ -119,18 +119,21 @@ BarcodeGenerator supports multiple .NET framework versions for maximum compatibi
119119
| **.NET Framework** | 4.6.2+ | Legacy Windows applications |
120120
| **.NET 6.0** | 6.0+ | Long-term support version |
121121
| **.NET 8.0** | 8.0+ | Latest stable version |
122+
| **.NET 10.0** | 10.0+ | Future-ready version |
122123

123124
---
124125

125126
## 🔄 Breaking Changes
126127

127-
### Version 2.0.0+
128+
### Version 2.1.0
128129

129-
**Important changes to be aware of when upgrading:**
130+
- **PolySharp Integration:** The library now includes the `PolySharp` package to enhance compatibility. If you encounter any issues, please report them by opening an issue on our GitHub repository. For more details, visit the [PolySharp GitHub repository](https://github.com/Sergio0694/PolySharp).
130131

131-
- **Framework Requirement:** No longer supports .NET Standard 1.3 (requires .NET Standard 2.0+)
132-
- **API Changes:** Redesigned for improved usability and customization
133-
- **SkiaSharp Update:** Updated to SkiaSharp 3.116.1 for better performance
132+
### Version 2.0.0
133+
134+
- **Framework Requirement:** No longer supports .NET Standard 1.3 (requires .NET Standard 2.0+).
135+
- **API Changes:** Redesigned for improved usability and customization.
136+
- **SkiaSharp Update:** Updated to SkiaSharp 3.116.1 for better performance.
134137

135138
> **📖 Migration Guide:** See our [Getting Started documentation](docs/getting-started.md) for updated API usage patterns.
136139
@@ -140,7 +143,6 @@ BarcodeGenerator supports multiple .NET framework versions for maximum compatibi
140143

141144
### Planned Features and Improvements
142145

143-
- [x] ~~Update the README.md documentation~~**Completed**
144146
- [ ] Add support for CODE39 and CODE128 encoders
145147
- [ ] Add support for more barcode types
146148
- [ ] Add an API to validate the barcode

Tests/TyKonKet.BarcodeGenerator.Benchmarks/TyKonKet.BarcodeGenerator.Benchmarks.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
18-
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.14.0" />
17+
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
18+
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.15.2" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

Tests/TyKonKet.BarcodeGenerator.CB/TyKonKet.BarcodeGenerator.CB.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
17+
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

Tests/TyKonKet.BarcodeGenerator.Playground/TyKonKet.BarcodeGenerator.Playground.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="SkiaSharp" Version="3.116.1" />
9+
<PackageReference Include="SkiaSharp" Version="3.119.0" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

Tests/TyKonKet.BarcodeGenerator.Tests/BarcodeOptionsTest.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,18 @@ public void UseTypefaceFromData_ShouldThrowException_WhenLocked()
7676
public void UseTypefaceFromStream_ShouldSetTypeface()
7777
{
7878
var options = new BarcodeOptions();
79-
using (var stream = new MemoryStream(new byte[] { 0 }))
80-
{
81-
options.UseTypefaceFromStream(stream);
82-
Assert.NotNull(options.Typeface);
83-
}
79+
using var stream = new MemoryStream([0]);
80+
options.UseTypefaceFromStream(stream);
81+
Assert.NotNull(options.Typeface);
8482
}
8583

8684
[Fact]
8785
public void UseTypefaceFromStream_ShouldThrowException_WhenLocked()
8886
{
8987
var options = new BarcodeOptions();
9088
options.Lock();
91-
using (var stream = new MemoryStream(new byte[] { 0 }))
92-
{
93-
Assert.Throws<InvalidOperationException>(() => options.UseTypefaceFromStream(stream));
94-
}
89+
using var stream = new MemoryStream([0]);
90+
Assert.Throws<InvalidOperationException>(() => options.UseTypefaceFromStream(stream));
9591
}
9692

9793
[Fact]
@@ -102,10 +98,8 @@ public void Lock_ShouldPreventModifications()
10298
Assert.Throws<InvalidOperationException>(() => options.UseTypeface(SKTypeface.FromFamilyName("Arial")));
10399
Assert.Throws<InvalidOperationException>(() => options.UseTypefaceFromFile("path/to/font.ttf"));
104100
Assert.Throws<InvalidOperationException>(() => options.UseTypefaceFromData(SKData.Create(1)));
105-
using (var stream = new MemoryStream(new byte[] { 0 }))
106-
{
107-
Assert.Throws<InvalidOperationException>(() => options.UseTypefaceFromStream(stream));
108-
}
101+
using var stream = new MemoryStream([0]);
102+
Assert.Throws<InvalidOperationException>(() => options.UseTypefaceFromStream(stream));
109103
}
110104
}
111105
}

Tests/TyKonKet.BarcodeGenerator.Tests/TyKonKet.BarcodeGenerator.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
<ItemGroup>
1010
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="all" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
1212
<PackageReference Include="xunit" Version="2.9.3" />
13-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
13+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
1717
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
18-
<PackageReference Include="coverlet.collector" Version="6.0.3" PrivateAssets="all" />
18+
<PackageReference Include="coverlet.collector" Version="6.0.4" PrivateAssets="all" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

TyKonKet.BarcodeGenerator/Attributes/BarcodeEncodingAttribute.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,20 @@ namespace TyKonKet.BarcodeGenerator.Attributes
66
/// Attribute to specify the encoding name for a barcode field.
77
/// This attribute can be applied to fields to indicate the type of barcode encoding used.
88
/// </summary>
9+
/// <remarks>
10+
/// Initializes a new instance of the <see cref="BarcodeEncodingAttribute"/> class
11+
/// with the specified barcode encoding name.
12+
/// </remarks>
13+
/// <param name="name">The name of the barcode encoding.</param>
914
[AttributeUsage(AttributeTargets.Field)]
10-
internal sealed class BarcodeEncodingAttribute : Attribute
15+
internal sealed class BarcodeEncodingAttribute(string name) : Attribute
1116
{
12-
/// <summary>
13-
/// Initializes a new instance of the <see cref="BarcodeEncodingAttribute"/> class
14-
/// with the specified barcode encoding name.
15-
/// </summary>
16-
/// <param name="name">The name of the barcode encoding.</param>
17-
public BarcodeEncodingAttribute(string name)
18-
{
19-
this.Name = name;
20-
}
21-
2217
/// <summary>
2318
/// Gets the name of the barcode encoding.
2419
/// </summary>
2520
/// <value>
2621
/// A <see cref="string"/> representing the name of the barcode encoding.
2722
/// </value>
28-
public string Name { get; }
23+
public string Name { get; } = name;
2924
}
3025
}

TyKonKet.BarcodeGenerator/Encoders/Abstract/EanEncoder.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,42 @@ internal abstract class EanEncoder : Encoder
1313
/// Encoding patterns for digits 0-9 using encoding set A.
1414
/// </summary>
1515
protected static readonly string[] EncodingA =
16-
{
16+
[
1717
"0001101", "0011001", "0010011", "0111101", "0100011",
1818
"0110001", "0101111", "0111011", "0110111", "0001011",
19-
};
19+
];
2020

2121
/// <summary>
2222
/// Encoding patterns for digits 0-9 using encoding set B.
2323
/// </summary>
2424
protected static readonly string[] EncodingB =
25-
{
25+
[
2626
"0100111", "0110011", "0011011", "0100001", "0011101",
2727
"0111001", "0000101", "0010001", "0001001", "0010111",
28-
};
28+
];
2929

3030
/// <summary>
3131
/// Encoding patterns for digits 0-9 using encoding set C.
3232
/// </summary>
3333
protected static readonly string[] EncodingC =
34-
{
34+
[
3535
"1110010", "1100110", "1101100", "1000010", "1011100",
3636
"1001110", "1010000", "1000100", "1001000", "1110100",
37-
};
37+
];
3838

3939
/// <summary>
4040
/// Encoding table for the first digit of EAN-13 barcodes.
4141
/// </summary>
4242
protected static readonly string[] EncodingTable =
43-
{
43+
[
4444
"000000", "001011", "001101", "001110", "010011",
4545
"011001", "011100", "010101", "010110", "011010",
46-
};
46+
];
4747

4848
/// <summary>
4949
/// Guard patterns used in EAN barcodes.
5050
/// </summary>
51-
protected static readonly string[] Guards = { "101", "01010", "101" };
51+
protected static readonly string[] Guards = ["101", "01010", "101"];
5252

5353
/// <summary>
5454
/// Gets the accepted character set for the barcode.
@@ -81,7 +81,7 @@ internal static string FormatBarcode(string barcode, int length)
8181
{
8282
length--;
8383
barcode = barcode.PadLeft(length, '0');
84-
barcode = barcode.Substring(0, length);
84+
barcode = barcode[..length];
8585

8686
return $"{barcode}{GetCheckDigit(barcode)}";
8787
}
@@ -96,7 +96,7 @@ internal static string GetCheckDigit(string barcode)
9696
var checkSumValue = 0;
9797
for (var i = 1; i <= barcode.Length; i++)
9898
{
99-
checkSumValue += (((i % 2) * 2) + 1) * barcode[barcode.Length - i].ToInt();
99+
checkSumValue += (((i % 2) * 2) + 1) * barcode[^i].ToInt();
100100
}
101101

102102
checkSumValue %= 10;

0 commit comments

Comments
 (0)