Allow CustomHandler to invoke static methods from matched types#41
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR extends the CustomHandler functionality to allow invoking static methods from matched types in addition to generic methods in the current type. The implementation adds support for detecting whether a custom handler should be a method in the current class or a static method in matched types.
- Added
CustomHandlerTypeenum to distinguish between method types (current class method vs. type method) - Updated attribute parsing to detect and handle both custom handler types
- Modified code generation to invoke static methods on matched types when appropriate
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| version.json | Bumps version from 2.2 to 2.3 |
| ServiceRegistrationModel.cs | Adds CustomHandlerType and TypeName properties to CustomHandlerModel |
| AttributeModel.cs | Adds CustomHandlerType enum and updates attribute parsing logic |
| GenerateAttributeInfo.cs | Updates documentation comments for better clarity |
| DiagnosticDescriptors.cs | Removes unused CustomHandlerMethodNotFound diagnostic |
| DependencyInjectionGenerator.cs | Updates code generation to handle both handler types |
| DependencyInjectionGenerator.ParseMethodModel.cs | Modifies validation logic for custom handlers |
| DependencyInjectionGenerator.FindServicesToRegister.cs | Updates custom handler creation with new properties |
| DependencyInjectionGenerator.FilterTypes.cs | Allows static types for TypeMethod custom handlers |
| CustomHandlerTests.cs | Adds comprehensive tests for static method handlers |
| README.md | Updates documentation to reflect new CustomHandler capabilities |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (customHandlerMethod.TypeParameters.Length > 1 | ||
| && customHandlerMethod.TypeParameters.Length != attribute.AssignableToTypeParametersCount + 1) | ||
| if (customHandlerMethod != null) | ||
| { |
There was a problem hiding this comment.
The validation logic only applies to Method type custom handlers but doesn't validate TypeMethod handlers. Consider adding validation for static methods in target types to ensure they exist and have correct signatures.
No description provided.