-
-
Notifications
You must be signed in to change notification settings - Fork 7
Allow CustomHandler to invoke static methods from matched types #41
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,27 +56,27 @@ public partial class DependencyInjectionGenerator | |
| var customHandlerMethod = method.ContainingType.GetMembers().OfType<IMethodSymbol>() | ||
| .FirstOrDefault(m => m.Name == attribute.CustomHandler); | ||
|
|
||
| if (customHandlerMethod is null) | ||
| return Diagnostic.Create(CustomHandlerMethodNotFound, attribute.Location); | ||
|
|
||
| if (!customHandlerMethod.IsGenericMethod) | ||
| return Diagnostic.Create(CustomHandlerMethodHasIncorrectSignature, attribute.Location); | ||
|
|
||
| var typesMatch = Enumerable.SequenceEqual( | ||
| method.Parameters.Select(p => p.Type), | ||
| customHandlerMethod.Parameters.Select(p => p.Type), | ||
| SymbolEqualityComparer.Default); | ||
|
|
||
| if (!typesMatch) | ||
| return Diagnostic.Create(CustomHandlerMethodHasIncorrectSignature, attribute.Location); | ||
|
|
||
| // If CustomHandler has more than 1 type parameters, we try to resolve them from | ||
| // matched assignableTo type arguments. | ||
| // e.g. ApplyConfiguration<T, TEntity>(ModelBuilder modelBuilder) where T : IEntityTypeConfiguration<TEntity> | ||
| if (customHandlerMethod.TypeParameters.Length > 1 | ||
| && customHandlerMethod.TypeParameters.Length != attribute.AssignableToTypeParametersCount + 1) | ||
| if (customHandlerMethod != null) | ||
| { | ||
|
||
| return Diagnostic.Create(CustomHandlerMethodHasIncorrectSignature, attribute.Location); | ||
| if (!customHandlerMethod.IsGenericMethod) | ||
| return Diagnostic.Create(CustomHandlerMethodHasIncorrectSignature, attribute.Location); | ||
|
|
||
| var typesMatch = Enumerable.SequenceEqual( | ||
| method.Parameters.Select(p => p.Type), | ||
| customHandlerMethod.Parameters.Select(p => p.Type), | ||
| SymbolEqualityComparer.Default); | ||
|
|
||
| if (!typesMatch) | ||
| return Diagnostic.Create(CustomHandlerMethodHasIncorrectSignature, attribute.Location); | ||
|
|
||
| // If CustomHandler has more than 1 type parameters, we try to resolve them from | ||
| // matched assignableTo type arguments. | ||
| // e.g. ApplyConfiguration<T, TEntity>(ModelBuilder modelBuilder) where T : IEntityTypeConfiguration<TEntity> | ||
| if (customHandlerMethod.TypeParameters.Length > 1 | ||
| && customHandlerMethod.TypeParameters.Length != attribute.AssignableToTypeParametersCount + 1) | ||
| { | ||
| return Diagnostic.Create(CustomHandlerMethodHasIncorrectSignature, attribute.Location); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,77 +4,70 @@ | |
|
|
||
| public static class DiagnosticDescriptors | ||
| { | ||
| public static readonly DiagnosticDescriptor NotPartialDefinition = new("DI0001", | ||
|
Check warning on line 7 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "Method is not partial", | ||
| "Method with GenerateServiceRegistrations attribute must have partial modifier", | ||
| "Usage", | ||
| DiagnosticSeverity.Error, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor WrongReturnType = new("DI0002", | ||
|
Check warning on line 14 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "Wrong return type", | ||
| "Method with GenerateServiceRegistrations attribute must return void or IServiceCollection", | ||
| "Usage", | ||
| DiagnosticSeverity.Error, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor WrongMethodParameters = new("DI0003", | ||
|
Check warning on line 21 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "Wrong method parameters", | ||
| "Method with GenerateServiceRegistrations attribute must have a single IServiceCollection parameter", | ||
| "Usage", | ||
| DiagnosticSeverity.Error, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor MissingSearchCriteria = new("DI0004", | ||
|
Check warning on line 28 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "Missing search criteria", | ||
| "GenerateServiceRegistrations must have at least one search criteria", | ||
| "Usage", | ||
| DiagnosticSeverity.Error, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor NoMatchingTypesFound = new("DI0005", | ||
|
Check warning on line 35 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "No matching types found", | ||
| "There are no types matching attribute's search criteria", | ||
| "Usage", | ||
| DiagnosticSeverity.Warning, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor KeySelectorMethodHasIncorrectSignature = new("DI0007", | ||
|
Check warning on line 42 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "Provided KeySelector method has incorrect signature", | ||
| "KeySelector should have non-void return type, and either be generic with no parameters, or non-generic with a single Type parameter", | ||
| "Usage", | ||
| DiagnosticSeverity.Error, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor CantMixRegularAndCustomHandlerRegistrations = new("DI0008", | ||
|
Check warning on line 49 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "It's not allowed to mix GenerateServiceRegistrations attributes with and without CustomHandler on the same method", | ||
| "It's not allowed to mix GenerateServiceRegistrations attributes with and without CustomHandler on the same method", | ||
| "Usage", | ||
| DiagnosticSeverity.Error, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor WrongReturnTypeForCustomHandler = new("DI0009", | ||
|
Check warning on line 56 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "Wrong return type", | ||
| "Method with CustomHandler must return void or the type of its first parameter", | ||
| "Usage", | ||
| DiagnosticSeverity.Error, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor CustomHandlerMethodNotFound = new("DI0012", | ||
| "Provided CustomHandler method is not found", | ||
| "CustomHandler parameter should point to a method in the class", | ||
| "Usage", | ||
| DiagnosticSeverity.Error, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor CustomHandlerMethodHasIncorrectSignature = new("DI0011", | ||
|
Check warning on line 63 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "Provided CustomHandler method has incorrect signature", | ||
| "CustomHandler method must be generic, and must have the same parameters as the method with the attribute", | ||
| "Usage", | ||
| DiagnosticSeverity.Error, | ||
| true); | ||
|
|
||
| public static readonly DiagnosticDescriptor CantUseBothFromAssemblyOfAndAssemblyNameFilter = new("DI0012", | ||
|
Check warning on line 70 in ServiceScan.SourceGenerator/DiagnosticDescriptors.cs
|
||
| "Only one assembly selection criteria allowed", | ||
| "It is not allowed to use both FromAssemblyOf and AssemblyNameFilter in the same attribute", | ||
| "Usage", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.