Skip to content

Commit 2112bb0

Browse files
authored
Release/v2.0.0
* - Release v2.0.0
1 parent 62c043c commit 2112bb0

15 files changed

Lines changed: 2296 additions & 343 deletions

.github/workflows/PR-CI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
beta_Version: ${{ steps.gitversion.outputs.nuGetVersion }}
3131
branchName: ${{ steps.gitversion.outputs.branchName }}
3232
env:
33-
working-directory: /home/runner/work/parsley.net/parsley.net
33+
working-directory: ${{ github.workspace }}
3434

3535
steps:
3636
- name: Step-01 Install GitVersion
@@ -87,7 +87,7 @@ jobs:
8787
env:
8888
github-token: '${{ secrets.GH_Packages }}'
8989
nuget-token: '${{ secrets.NUGET_API_KEY }}'
90-
working-directory: /home/runner/work/parsley.net/parsley.net
90+
working-directory: ${{ github.workspace }}
9191
steps:
9292
- name: Step-01 Retrieve Build Artifacts
9393
uses: actions/download-artifact@v4
@@ -108,7 +108,7 @@ jobs:
108108
runs-on: ubuntu-latest
109109
env:
110110
nuget-token: '${{ secrets.NUGET_API_KEY }}'
111-
working-directory: /home/runner/work/parsley.net/parsley.net
111+
working-directory: ${{ github.workspace }}
112112
steps:
113113
- name: Step-01 Retrieve Build Artifacts
114114
uses: actions/download-artifact@v4

GitVersion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
next-version: 1.1.5
1+
next-version: 2.0.0
22
tag-prefix: '[vV]'
33
mode: ContinuousDeployment
44
branches:

Parsley.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,201 @@ public class NameType
192192
```
193193
Now parsing the file should hydrate data correctly to the Employee FileLine class and its nested name type.
194194

195+
## Parsley.Net v2.0.0 - Major Release Features
196+
197+
Parsley.Net v2.0.0 represents a comprehensive evolution of the library with enhanced functionality while maintaining complete backward compatibility. This major release introduces new configuration options, improved error handling, and better performance.
198+
199+
### 1. Enhanced Error Reporting with Line Numbers
200+
201+
The v2.0.0 release significantly improves error reporting by providing line numbers and field names in error messages:
202+
203+
```
204+
public class EnhancedErrorExample : IFileLine
205+
{
206+
[Column(0)]
207+
public string Code { get; set; }
208+
209+
[Column(1)]
210+
public NameType Name { get; set; }
211+
212+
public int Index { get; set; }
213+
public IList<string> Errors { get; set; }
214+
}
215+
216+
// Usage - error messages now include line numbers and field details
217+
var parser = new Parser('|');
218+
var lines = new[] { "GB-01|Invalid Name Format", "XX-99|Another Invalid Entry" };
219+
220+
var result = parser.Parse<EnhancedErrorExample>(lines);
221+
222+
foreach (var item in result)
223+
{
224+
if (item.Errors?.Any() == true)
225+
{
226+
Console.WriteLine($"Line {item.Index}: {string.Join(", ", item.Errors)}");
227+
// Example: "Line 1: Name failed to parse - Invalid name format in value 'Invalid Name Format'"
228+
}
229+
}
230+
```
231+
232+
### 2. ParseOptions Configuration Class
233+
234+
Introducing `ParseOptions` to configure parsing behavior with various options:
235+
236+
```
237+
public class ParseOptions
238+
{
239+
public char Delimiter { get; set; } = ','; // Default delimiter
240+
public bool SkipHeaderLine { get; set; } = false; // Skip first line as header
241+
public bool TrimFieldValues { get; set; } = true; // Trim whitespace from values
242+
public bool IncludeEmptyLines { get; set; } = true; // Include empty lines in output
243+
public int MaxErrors { get; set; } = -1; // Max errors to collect (-1 for unlimited)
244+
public int BufferSize { get; set; } = 1024; // Buffer size for streaming operations
245+
}
246+
247+
// Usage examples
248+
var customParser = new Parser();
249+
250+
// Parse with custom options
251+
var options = new ParseOptions
252+
{
253+
Delimiter = '|',
254+
SkipHeaderLine = true,
255+
TrimFieldValues = true,
256+
IncludeEmptyLines = false,
257+
MaxErrors = 100
258+
};
259+
260+
var result = await parser.ParseAsync<Employee>("data.csv", options);
261+
```
262+
263+
### 3. TryParse and TryParseAsync Methods
264+
265+
New methods added for more explicit error handling using the result pattern:
266+
267+
```
268+
// Synchronous TryParse methods
269+
public Result<T[]> TryParse<T>(string filepath) where T : IFileLine, new();
270+
public Result<T[]> TryParse<T>(string filepath, ParseOptions options) where T : IFileLine, new();
271+
public Result<T[]> TryParse<T>(string[] lines) where T : IFileLine, new();
272+
public Result<T[]> TryParse<T>(string[] lines, ParseOptions options) where T : IFileLine, new();
273+
public Result<T[]> TryParse<T>(byte[] bytes, Encoding encoding = null) where T : IFileLine, new();
274+
public Result<T[]> TryParse<T>(byte[] bytes, Encoding encoding, ParseOptions options) where T : IFileLine, new();
275+
public Result<T[]> TryParse<T>(Stream stream, Encoding encoding = null) where T : IFileLine, new();
276+
public Result<T[]> TryParse<T>(Stream stream, Encoding encoding, ParseOptions options) where T : IFileLine, new();
277+
278+
// Asynchronous TryParse methods
279+
public async Task<Result<T[]>> TryParseAsync<T>(string filepath) where T : IFileLine, new();
280+
public async Task<Result<T[]>> TryParseAsync<T>(string filepath, ParseOptions options) where T : IFileLine, new();
281+
public async Task<Result<T[]>> TryParseAsync<T>(string[] lines) where T : IFileLine, new();
282+
public async Task<Result<T[]>> TryParseAsync<T>(string[] lines, ParseOptions options) where T : IFileLine, new();
283+
public async Task<Result<T[]>> TryParseAsync<T>(byte[] bytes, Encoding encoding = null) where T : IFileLine, new();
284+
public async Task<Result<T[]>> TryParseAsync<T>(byte[] bytes, Encoding encoding, ParseOptions options) where T : IFileLine, new();
285+
public async Task<Result<T[]>> TryParseAsync<T>(Stream stream, Encoding encoding = null) where T : IFileLine, new();
286+
public async Task<Result<T[]>> TryParseAsync<T>(Stream stream, Encoding encoding, ParseOptions options) where T : IFileLine, new();
287+
288+
// Usage example with TryParse
289+
var parser = new Parser('|');
290+
291+
// Safe parsing without throwing exceptions
292+
var result = parser.TryParse<Employee>("employees.csv");
293+
294+
if (result.IsSuccess)
295+
{
296+
var employees = result.Value;
297+
Console.WriteLine($"Successfully parsed {employees.Length} employees");
298+
299+
// Check for individual record errors
300+
var validRecords = employees.Where(e => e.Errors?.Any() != true).ToArray();
301+
var errorRecords = employees.Where(e => e.Errors?.Any() == true).ToArray();
302+
303+
Console.WriteLine($"Valid records: {validRecords.Length}, Error records: {errorRecords.Length}");
304+
}
305+
else
306+
{
307+
// Global parsing errors occurred
308+
Console.WriteLine($"Parsing failed: {result.Error}");
309+
foreach (var error in result.Errors)
310+
{
311+
Console.WriteLine($" - {error}");
312+
}
313+
}
314+
```
315+
316+
### 4. Result Pattern Implementation
317+
318+
The `Result<T>` class provides explicit success/failure semantics:
319+
320+
```
321+
public class Result<T>
322+
{
323+
public bool IsSuccess { get; }
324+
public bool IsFailure => !IsSuccess;
325+
public T Value { get; }
326+
public IList<string> Errors { get; }
327+
328+
public static Result<T> Success(T value);
329+
public static Result<T> Failure(string error);
330+
public static Result<T> Failure(IList<string> errors);
331+
public static Result<T> Failure(string error, IList<string> errors);
332+
}
333+
334+
// Examples:
335+
var successResult = Result<string>.Success("Operation completed successfully");
336+
var errorResult = Result<Employee[]>.Failure("File not found");
337+
```
338+
339+
### 5. Configuration Options Usage
340+
341+
The new ParseOptions class allows for flexible parsing configurations:
342+
343+
```
344+
// Example 1: CSV with headers, skipping first line
345+
var csvOptions = new ParseOptions
346+
{
347+
Delimiter = ',',
348+
SkipHeaderLine = true
349+
};
350+
var csvResult = parser.Parse<Employee>("employees.csv", csvOptions);
351+
352+
// Example 2: TSV with tab delimiter, no trimming
353+
var tsvOptions = new ParseOptions
354+
{
355+
Delimiter = '\t',
356+
TrimFieldValues = false
357+
};
358+
var tsvResult = parser.Parse<DataRecord>("data.tsv", tsvOptions);
359+
360+
// Example 3: PSV with pipe delimiter, limiting errors
361+
var psvOptions = new ParseOptions
362+
{
363+
Delimiter = '|',
364+
MaxErrors = 50,
365+
IncludeEmptyLines = false
366+
};
367+
var psvResult = await parser.TryParseAsync<Employee>("data.psv", psvOptions);
368+
```
369+
370+
### 6. Backward Compatibility
371+
372+
All v2.0.0 changes maintain complete backward compatibility:
373+
374+
```
375+
// All existing code continues to work unchanged
376+
var parser = new Parser('|');
377+
var employees = parser.Parse<Employee>("employees.csv"); // Still works
378+
var employeesAsync = await parser.ParseAsync<Employee>("employees.csv"); // Still works
379+
380+
// New functionality builds upon existing methods
381+
var tryResult = parser.TryParse<Employee>("employees.csv"); // New in v2.0.0
382+
```
383+
384+
### Migration Guide
385+
386+
Upgrading from v1.x to v2.0.0 is seamless for existing code:
387+
388+
1. **Existing code**: No changes required - all previous APIs remain the same
389+
2. **New features**: Gradually adopt TryParse methods and ParseOptions for enhanced functionality
390+
3. **Better error handling**: Switch to TryParse methods where more explicit error handling is needed
391+
195392

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# <img src="https://github.com/CodeShayk/parsley.net/blob/master/Images/ninja-icon-16.png" alt="ninja" style="width:30px;"/> Parsley.Net v1.1.5
1+
# <img src="https://github.com/CodeShayk/parsley.net/blob/master/Images/ninja-icon-16.png" alt="ninja" style="width:30px;"/> Parsley.Net v2.0.0
22
[![NuGet version](https://badge.fury.io/nu/Parsley.Net.svg)](https://badge.fury.io/nu/Parsley.Net) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/CodeShayk/Parsley.Net/blob/master/LICENSE.md)
33
[![GitHub Release](https://img.shields.io/github/v/release/CodeShayk/Parsley.Net?logo=github&sort=semver)](https://github.com/CodeShayk/Parsley.Net/releases/latest)
44
[![master-build](https://github.com/CodeShayk/parsley.net/actions/workflows/Master-Build.yml/badge.svg)](https://github.com/CodeShayk/parsley.net/actions/workflows/Master-Build.yml)
@@ -48,12 +48,14 @@ If you are having problems, please let me know by [raising a new issue](https://
4848
This project is licensed with the [MIT license](LICENSE).
4949

5050
## Version History
51-
The main branch is now on .NET 9.0.
52-
| Version | Release Notes |
53-
| -------- | --------|
54-
| [`v1.0.0`](https://github.com/CodeShayk/parsley.net/tree/v1.0.0) | [Notes](https://github.com/CodeShayk/Parsley.Net/releases/tag/v1.0.0) |
55-
| [`v1.1.0`](https://github.com/CodeShayk/parsley.net/tree/v1.1.0) | [Notes](https://github.com/CodeShayk/Parsley.Net/releases/tag/v1.1.0) |
51+
The main branch is now on .NET 9.0.
52+
53+
| Version | Release Notes |
54+
| ---------------------------------------------------------------- | -----------------------------------------------------------------------|
55+
| [`v2.0.0`](https://github.com/CodeShayk/parsley.net/tree/v2.0.0) | [Notes](https://github.com/CodeShayk/Parsley.Net/releases/tag/v2.0.0) - MAJOR RELEASE: Comprehensive release with enhanced error reporting, improved performance, configuration options and result pattern |
5656
| [`v1.1.5`](https://github.com/CodeShayk/parsley.net/tree/v1.1.5) | [Notes](https://github.com/CodeShayk/Parsley.Net/releases/tag/v1.1.5) |
57+
| [`v1.1.0`](https://github.com/CodeShayk/parsley.net/tree/v1.1.0) | [Notes](https://github.com/CodeShayk/Parsley.Net/releases/tag/v1.1.0) |
58+
| [`v1.0.0`](https://github.com/CodeShayk/parsley.net/tree/v1.0.0) | [Notes](https://github.com/CodeShayk/Parsley.Net/releases/tag/v1.0.0) |
5759

5860
## Credits
5961
Thank you for reading. Please fork, explore, contribute and report. Happy Coding !! :)

0 commit comments

Comments
 (0)