Skip to content

Add extension methods.#17

Open
jlbarreda wants to merge 6 commits into
mainfrom
new-features
Open

Add extension methods.#17
jlbarreda wants to merge 6 commits into
mainfrom
new-features

Conversation

@jlbarreda
Copy link
Copy Markdown
Owner

PR Classification

New feature, documentation, and code cleanup.

PR Summary

This pull request introduces new utility methods for argument validation, string manipulation, time handling, and type analysis, along with enhanced documentation and test coverage. It also includes code refactoring to align with modern C# practices.

  • NumberBaseExtensions: Added ThrowIfZero methods for numeric validation and updated documentation.
  • StringExtensions: Added methods like IsNotNull, IsNullOrEmpty, and ThrowIfNullOrWhiteSpace for string validation.
  • TimeProviderExtensions: Added methods like Freeze, GetToday, and GetUtcNowAsDateTime for time handling.
  • TypeExtensions: Added methods for type analysis, such as GetFriendlyTypeName, IsIEnumerableOfT, and TryGetTypeOfTFromIEnumerableOfT.
  • Unit Tests: Added comprehensive tests for DateTimeOffsetExtensions, TimeProviderExtensions, and TypeExtensions.

Added new extensions for argument validation, logging, and type utilities. Introduced `NumberBaseExtensions`, `StringExtensions`, `TimeProviderExtensions`, and `TypeExtensions` with methods for validation, formatting, and conversions. Enhanced documentation and added comprehensive tests for all new features.

### Key Changes:
- `NumberBaseExtensions`: Added methods like `ThrowIfNegative`, `ThrowIfZero`, etc.
- `StringExtensions`: Added methods like `IsNotNull`, `ThrowIfNullOrEmpty`, etc.
- `TimeProviderExtensions`: Added methods like `Freeze`, `GetUtcNowAsDateTime`, etc.
- `TypeExtensions`: Added methods like `GetTypeName`, `IsIEnumerableOfT`, etc.
- Added `BuiltInTypeAliasMap` for C# keyword aliases.
- Comprehensive documentation updates and new tests for all methods.
Introduced `IRoundRobinGenerator<T>` interface and two implementations:
- `RoundRobinGeneratorBase<T>`: Base class for round-robin generators.
- `RoundRobinNumberGenerator<T>`: Numeric round-robin generator.

Added `SerializableExceptionWrapper` for serializing exceptions, including properties and inner exceptions.

Updated `.editorconfig` and `copilot-instructions.md` to enforce consistent coding styles and guidelines.

Refactored private field naming conventions in `LogMessageScope` and `FrozenTimeProvider`.

Added comprehensive tests for round-robin generators and exception wrapper.
Introduced the `EnterCatch` class in the `DevElf` namespace, providing utility methods for executing actions in `catch` block filter conditions. Added the following methods:

- `Never(Action)`: Executes an action and prevents the `catch` block from being entered.
- `AfterAction(Action)`: Executes an action and ensures the `catch` block is entered.
- `AfterActionIf(Action, Func<bool>)`: Executes an action and conditionally determines whether the `catch` block is entered.

Updated `DevElf.md` with detailed documentation for the `EnterCatch` class and its methods, including examples and remarks. Highlighted limitations with async code and referenced Stephen Cleary's blog post on exception logging patterns.

Added comprehensive unit tests in `EnterCatchTests.cs` to verify the behavior of all methods, including null argument validation, exception context preservation, and conditional handling logic.
The `using DevElf.ArgumentValidation;` directive in `EnterCatch.cs` was removed and re-added without any functional changes. This appears to address a formatting or encoding issue, as the directive remains unchanged in functionality.
Introduced `NoLimitRateLimiter` and `RateLimiterExtensions` to simplify rate limiting for actions and requests.
Added `LoggerExtensions` for fluent logging scope creation and `ServiceCollectionExtensions` for enhanced DI patterns.

Comprehensive unit tests were added for all new features, ensuring robust validation of edge cases and concurrency.
Updated documentation with examples and details for new classes and methods.

Upgraded dependencies, including `System.Threading.RateLimiting`, and updated project files to include new namespaces.
Updated method names in `LoggingScopePropertiesBuilderTests` to follow PascalCase naming conventions for consistency.
Replaced `ToArray()` with modern syntax `[.. capturedProperties.Keys]` for asserting key order in tests.
No functional changes were made to the test logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant