-
Notifications
You must be signed in to change notification settings - Fork 0
Fix DocFX configuration and add documentation content #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
316c3e7
Fix DocFX configuration and add documentation content
Chris-Wolfgang a592770
Address Copilot review: fix API links, base URL, and prerequisites
Chris-Wolfgang 5476f6c
Merge branch 'main' into docs/fix-docfx-configuration
Chris-Wolfgang 9d8e391
Trigger CI
Chris-Wolfgang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # DocFX build output — generated by `docfx build` | ||
| * | ||
| !.gitignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # DocFX auto-generated metadata files — rebuilt by `docfx metadata` | ||
| *.yml | ||
| !.gitignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # API Reference | ||
|
|
||
| Welcome to the Wolfgang.TryPattern API documentation. | ||
|
|
||
| This section contains the complete API reference, automatically generated from XML documentation comments in the source code. | ||
|
|
||
| Browse the navigation menu to explore available namespaces and types. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| For usage examples and guides, see the [Documentation](../docs/getting-started.md) section. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,143 @@ | ||
| # Getting Started | ||
| # Getting Started | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - .NET 10 SDK or later (required to build and test this repository, because the library multi-targets .NET 10.0) | ||
| - Any project targeting .NET Framework 4.6.2+, .NET Standard 2.0, .NET 8.0, or .NET 10.0 | ||
|
|
||
| ## Installation | ||
|
|
||
| ### Package Manager Console | ||
|
|
||
| ```powershell | ||
| Install-Package Wolfgang.TryPattern | ||
| ``` | ||
|
|
||
| ### .NET CLI | ||
|
|
||
| ```bash | ||
| dotnet add package Wolfgang.TryPattern | ||
| ``` | ||
|
|
||
| ### PackageReference | ||
|
|
||
| ```xml | ||
| <PackageReference Include="Wolfgang.TryPattern" Version="0.2.0" /> | ||
| ``` | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ### Running an Action | ||
|
|
||
| Use `Try.Run` to execute an action that might throw: | ||
|
|
||
| ```csharp | ||
| using Wolfgang.TryPattern; | ||
|
|
||
| var result = Try.Run(() => File.Delete(tempPath)); | ||
|
|
||
| if (result.Failed) | ||
| { | ||
| Console.WriteLine($"Could not delete file: {result.ErrorMessage}"); | ||
| } | ||
| ``` | ||
|
|
||
| ### Running a Function | ||
|
|
||
| Use `Try.Run<T>` to execute a function and capture its return value: | ||
|
|
||
| ```csharp | ||
| var result = Try.Run(() => int.Parse(userInput)); | ||
|
|
||
| if (result.Succeeded) | ||
| { | ||
| Console.WriteLine($"Parsed value: {result.Value}"); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine($"Invalid input: {result.ErrorMessage}"); | ||
| } | ||
| ``` | ||
|
|
||
| ### Async Operations | ||
|
|
||
| Both `Action` and `Func<Task<T>>` have async counterparts: | ||
|
|
||
| ```csharp | ||
| var result = await Try.RunAsync( | ||
| () => httpClient.GetStringAsync(url) | ||
| ); | ||
|
|
||
| if (result.Succeeded) | ||
| { | ||
| ProcessResponse(result.Value); | ||
| } | ||
| ``` | ||
|
|
||
| Async operations support cancellation: | ||
|
|
||
| ```csharp | ||
| var result = await Try.RunAsync( | ||
| () => httpClient.GetStringAsync(url), | ||
| cancellationToken | ||
| ); | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > `OperationCanceledException` is intentionally **not** caught by `Try.RunAsync`. Cancellation propagates normally so callers can distinguish between a failed operation and a cancelled one. | ||
|
|
||
| ### Composing Results | ||
|
|
||
| When you need to run multiple operations and check the overall outcome: | ||
|
|
||
| ```csharp | ||
| var result1 = Try.Run(() => ValidateName(name)); | ||
| var result2 = Try.Run(() => ValidateEmail(email)); | ||
| var result3 = Try.Run(() => ValidateAge(age)); | ||
|
|
||
| // Check if any failed | ||
| if (Result.AnyFailed(result1, result2, result3)) | ||
| { | ||
| Console.WriteLine("Validation errors occurred."); | ||
| } | ||
|
|
||
| // Or flatten into a single result with combined error messages | ||
| var combined = Result.Flatten(result1, result2, result3); | ||
|
|
||
| if (combined.Failed) | ||
| { | ||
| // ErrorMessage contains all failure messages joined by newlines | ||
| Console.WriteLine(combined.ErrorMessage); | ||
| } | ||
| ``` | ||
|
|
||
| ### Creating Results Directly | ||
|
|
||
| You can also create `Result` objects directly for your own methods: | ||
|
|
||
| ```csharp | ||
| public Result ValidateOrder(Order order) | ||
| { | ||
| if (order.Items.Count == 0) | ||
| { | ||
| return Result.Failure("Order must contain at least one item."); | ||
| } | ||
|
|
||
| return Result.Success(); | ||
| } | ||
|
|
||
| public Result<decimal> CalculateDiscount(Order order) | ||
| { | ||
| if (order.Total < 50) | ||
| { | ||
| return Result<decimal>.Failure("Minimum order for discount is $50."); | ||
| } | ||
|
|
||
| return Result<decimal>.Success(order.Total * 0.10m); | ||
| } | ||
| ``` | ||
|
|
||
| ## Next Steps | ||
|
|
||
| - Browse the [API Reference](../api/index.md) for complete method signatures and XML documentation | ||
| - View the [source code](https://github.com/Chris-Wolfgang/Try-Pattern) on GitHub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Wolfgang.TryPattern Documentation | ||
|
|
||
| Welcome to the documentation section. Browse the topics in the navigation menu to get started. | ||
|
|
||
| ## Available Documentation | ||
|
|
||
| - [Introduction](introduction.md) - Overview and introduction | ||
| - [Getting Started](getting-started.md) - Quick start guide |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,79 @@ | ||
| # Introduction | ||
| # Introduction | ||
|
|
||
| Wolfgang.TryPattern is a lightweight .NET library that brings structured error handling to your codebase through the Try pattern. It replaces scattered try/catch blocks with a clean, composable API that makes error handling explicit and predictable. | ||
|
|
||
| ## The Problem | ||
|
|
||
| Traditional .NET error handling relies on try/catch blocks that can obscure control flow, make it difficult to compose operations, and lead to inconsistent error handling across a codebase: | ||
|
|
||
| ```csharp | ||
| string content; | ||
| try | ||
| { | ||
| content = File.ReadAllText(path); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| // Now what? Log? Return null? Throw a different exception? | ||
| logger.LogError(ex, "Failed to read file"); | ||
| return null; | ||
| } | ||
| ``` | ||
|
|
||
| ## The Solution | ||
|
|
||
| Wolfgang.TryPattern wraps operations in `Try.Run` and returns a `Result` object that clearly communicates the outcome: | ||
|
|
||
| ```csharp | ||
| var result = Try.Run(() => File.ReadAllText(path)); | ||
|
|
||
| if (result.Succeeded) | ||
| { | ||
| Console.WriteLine(result.Value); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine($"Error: {result.ErrorMessage}"); | ||
| } | ||
| ``` | ||
|
|
||
| ## Core Types | ||
|
|
||
| ### `Try` | ||
|
|
||
| A static class providing methods to execute actions and functions with automatic exception handling: | ||
|
|
||
| - **`Try.Run(Action)`** - Execute an action, returning a `Result` | ||
| - **`Try.Run<T>(Func<T>)`** - Execute a function, returning a `Result<T>` with the return value | ||
| - **`Try.RunAsync(Action, CancellationToken)`** - Execute an action asynchronously | ||
| - **`Try.RunAsync<T>(Func<Task<T>>, CancellationToken)`** - Execute an async function | ||
|
|
||
| ### `Result` | ||
|
|
||
| Represents the outcome of an operation: | ||
|
|
||
| - **`Succeeded`** - `true` if the operation completed without exceptions | ||
| - **`Failed`** - `true` if the operation threw an exception | ||
| - **`ErrorMessage`** - The exception message if the operation failed | ||
|
|
||
| ### `Result<T>` | ||
|
|
||
| Extends `Result` with a typed return value: | ||
|
|
||
| - **`Value`** - The return value from the function (throws `InvalidOperationException` if accessed on a failed result) | ||
|
|
||
| ### Composition Helpers | ||
|
|
||
| - **`Result.Flatten(params Result[])`** - Combine multiple results into one; if any failed, the error messages are joined | ||
| - **`Result.AnyFailed(params Result[])`** - Check if any result in a set indicates failure | ||
| - **`Result.AllSucceeded(params Result[])`** - Check if every result in a set indicates success | ||
|
|
||
| ## Platform Support | ||
|
|
||
| Wolfgang.TryPattern targets multiple frameworks for broad compatibility: | ||
|
|
||
| | Target | Version | | ||
| |--------|---------| | ||
| | .NET Framework | 4.6.2+ | | ||
| | .NET Standard | 2.0 | | ||
| | .NET | 8.0, 10.0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| - name: Index | ||
| href: Index.md | ||
| href: index.md | ||
| - name: Introduction | ||
| href: introduction.md | ||
| - name: Getting Started | ||
| href: getting-started.md | ||
| - name: Project website | ||
| href: https://github.com/Chris-Wolfgang/DbContextBuilder | ||
| href: 'https://github.com/Chris-Wolfgang/Try-Pattern' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.