-
Notifications
You must be signed in to change notification settings - Fork 0
Add lowercase documentation files for improved accessibility #51
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
Chris-Wolfgang
merged 5 commits into
main
from
copilot/add-getting-started-introduction
Jan 29, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
218293a
Initial plan
Copilot a1ae21a
Create getting-started.md, introduction.md, readme.md, setup.md files
Copilot 07c976e
Fix grammar, code examples, and link references in documentation
Copilot 5830730
Update documentation to reflect .NET 4.6.2 through .NET 10 support
Copilot 3ad3007
Add compatibility sections to readme.md and introduction.md
Copilot 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,208 @@ | ||||||
| # Getting Started | ||||||
|
|
||||||
| This guide will help you get up and running with the Try Pattern library in just a few minutes. | ||||||
|
|
||||||
| ## Installation | ||||||
|
|
||||||
| ### NuGet Package | ||||||
|
|
||||||
| Install the Try Pattern library via NuGet Package Manager: | ||||||
|
|
||||||
| ```bash | ||||||
| dotnet add package Wolfgang.TryPattern | ||||||
| ``` | ||||||
|
|
||||||
| Or using the Package Manager Console: | ||||||
|
|
||||||
| ```powershell | ||||||
| Install-Package Wolfgang.TryPattern | ||||||
| ``` | ||||||
|
|
||||||
| ### Manual Installation | ||||||
|
|
||||||
| Alternatively, you can clone the repository and reference the project directly: | ||||||
|
|
||||||
| ```bash | ||||||
| git clone https://github.com/Chris-Wolfgang/Try-Pattern.git | ||||||
| ``` | ||||||
|
|
||||||
| ## Basic Usage | ||||||
|
|
||||||
| ### 1. Using Try with Async Operations | ||||||
|
|
||||||
| The most common use case is wrapping async operations that may fail: | ||||||
|
|
||||||
| ```csharp | ||||||
| using Wolfgang.TryPattern; | ||||||
|
|
||||||
| // Reading a file that might not exist | ||||||
| var result = await Try.RunAsync(() => File.ReadAllTextAsync("data.txt")); | ||||||
|
|
||||||
| if (result.Succeeded) | ||||||
| { | ||||||
| Console.WriteLine($"File content: {result.Value}"); | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| Console.WriteLine($"Failed to read file: {result.ErrorMessage}"); | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ### 2. Using Try with Synchronous Operations | ||||||
|
|
||||||
| You can also use the Try Pattern with synchronous operations: | ||||||
|
|
||||||
| ```csharp | ||||||
| using Wolfgang.TryPattern; | ||||||
|
|
||||||
| // Parsing a JSON file | ||||||
| var result = Try.Run(() => JsonSerializer.Deserialize<MyData>(jsonString)); | ||||||
|
|
||||||
| if (result.Succeeded) | ||||||
| { | ||||||
| ProcessData(result.Value); | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| LogError(result.ErrorMessage); | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ### 3. Using Result for Custom Methods | ||||||
|
|
||||||
| Use `Result` and `Result<T>` as return types for your own methods: | ||||||
|
|
||||||
| ```csharp | ||||||
| using Wolfgang.TryPattern; | ||||||
|
|
||||||
| public Result ValidateEmail(string email) | ||||||
| { | ||||||
| if (string.IsNullOrWhiteSpace(email)) | ||||||
| { | ||||||
| return Result.Failure("Email cannot be empty"); | ||||||
| } | ||||||
|
|
||||||
| if (!email.Contains("@")) | ||||||
| { | ||||||
| return Result.Failure("Email must contain @"); | ||||||
| } | ||||||
|
|
||||||
| return Result.Success(); | ||||||
| } | ||||||
|
|
||||||
| public Result<User> GetUser(int userId) | ||||||
| { | ||||||
| var user = database.FindUser(userId); | ||||||
|
|
||||||
| if (user == null) | ||||||
| { | ||||||
| return Result<User>.Failure("User not found"); | ||||||
| } | ||||||
|
|
||||||
| return Result<User>.Success(user); | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ## Common Patterns | ||||||
|
|
||||||
| ### Pattern 1: File Operations | ||||||
|
|
||||||
| ```csharp | ||||||
| var result = await Try.RunAsync(() => File.ReadAllTextAsync(filePath)); | ||||||
| if (!result.Succeeded) | ||||||
| { | ||||||
| // Handle failure - file doesn't exist, no permissions, etc. | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| // Process the file content | ||||||
| var content = result.Value; | ||||||
| ``` | ||||||
|
|
||||||
| ### Pattern 2: HTTP Requests | ||||||
|
|
||||||
| ```csharp | ||||||
| public async Task<Result<string>> FetchDataAsync(string url) | ||||||
| { | ||||||
| using var response = await httpClient.GetAsync(url); | ||||||
|
|
||||||
| if (!response.IsSuccessStatusCode) | ||||||
| { | ||||||
| return Result<string>.Failure($"HTTP {response.StatusCode}"); | ||||||
| } | ||||||
|
|
||||||
| var content = await response.Content.ReadAsStringAsync(); | ||||||
|
||||||
| var content = await response.Content.ReadAsStringAsync(); | |
| var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); |
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,85 @@ | ||
| # Introduction | ||
|
|
||
| Welcome to the Try Pattern library! This library provides a simple and effective way to implement the Try Pattern in your C# applications. | ||
|
|
||
| ## What is the Try Pattern? | ||
|
|
||
| The Try Pattern is a design pattern where code execution returns success/failure status without exposing detailed exception information to the caller. This is particularly useful when: | ||
|
|
||
| - The caller only needs to know if an operation succeeded or failed | ||
| - The specific reason for failure is not relevant to the caller | ||
| - You want to avoid using exceptions for control flow | ||
|
|
||
| ## Why Use the Try Pattern? | ||
|
|
||
| ### Benefits | ||
|
|
||
| 1. **Simplified Error Handling**: No need to catch and handle specific exceptions | ||
| 2. **Cleaner Code**: Reduces try-catch blocks throughout your codebase | ||
| 3. **Better Performance**: Avoids the overhead of exception creation for expected failures | ||
| 4. **Clearer Intent**: Makes it explicit that an operation may fail | ||
|
|
||
| ### Real-World Examples | ||
|
|
||
| You're already familiar with the Try Pattern from .NET's built-in types: | ||
| - `int.TryParse(string, out int)` | ||
| - `DateTime.TryParse(string, out DateTime)` | ||
| - `Dictionary<TKey, TValue>.TryGetValue(TKey, out TValue)` | ||
|
|
||
| ## How This Library Helps | ||
|
|
||
| This library extends the Try Pattern to any operation by providing: | ||
|
|
||
| 1. **`Try` Class**: Static helper methods to execute operations and handle exceptions | ||
| 2. **`Result` Type**: Represents the outcome of an operation without a return value | ||
| 3. **`Result<T>` Type**: Represents the outcome of an operation that returns a value | ||
|
|
||
| ### Compatibility | ||
|
|
||
| The library supports .NET Framework 4.6.2 through .NET 10.0, including: | ||
| - .NET Framework 4.6.2 and later | ||
| - .NET Standard 2.0 | ||
| - .NET 8.0 | ||
| - .NET 10.0 | ||
|
|
||
| ## Quick Example | ||
|
|
||
| ```csharp | ||
| // Without Try Pattern - traditional approach | ||
| try | ||
| { | ||
| var content = await File.ReadAllTextAsync("config.json"); | ||
| ProcessConfig(content); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine("Error reading config: " + ex.Message); | ||
| } | ||
|
|
||
| // With Try Pattern - simplified approach | ||
| var result = await Try.RunAsync(() => File.ReadAllTextAsync("config.json")); | ||
| if (result.Succeeded) | ||
| { | ||
| ProcessConfig(result.Value); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("Error reading config: " + result.ErrorMessage); | ||
| } | ||
| ``` | ||
|
|
||
| ## When to Use the Try Pattern | ||
|
|
||
| **Use the Try Pattern when:** | ||
| - Operations may fail in expected ways (file not found, network timeout, etc.) | ||
| - The caller only needs success/failure information | ||
| - You want to avoid exception-based control flow | ||
|
|
||
| **Don't use the Try Pattern when:** | ||
| - You need specific exception details for different error handling | ||
| - The failure is truly exceptional and should propagate up the call stack | ||
| - You're dealing with programming errors (null arguments, invalid state) | ||
|
|
||
| ## Next Steps | ||
|
|
||
| Ready to get started? Check out the [Getting Started](getting-started.md) guide to learn how to install and use the library in your projects. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The async call to
httpClient.GetAsync(url)should useConfigureAwait(false)to avoid potential deadlocks in synchronization contexts. According to the project's coding guidelines, async methods should use ConfigureAwait(false).Change to: