Add extension methods.#17
Open
jlbarreda wants to merge 6 commits into
Open
Conversation
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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: AddedThrowIfZeromethods for numeric validation and updated documentation.StringExtensions: Added methods likeIsNotNull,IsNullOrEmpty, andThrowIfNullOrWhiteSpacefor string validation.TimeProviderExtensions: Added methods likeFreeze,GetToday, andGetUtcNowAsDateTimefor time handling.TypeExtensions: Added methods for type analysis, such asGetFriendlyTypeName,IsIEnumerableOfT, andTryGetTypeOfTFromIEnumerableOfT.DateTimeOffsetExtensions,TimeProviderExtensions, andTypeExtensions.