Add global generic constraint support to type relationship helpers#1199
Merged
Conversation
- Update InheritsFrom, Implements, ImplementsGenericInterface, IsOrImplements, and IsOrInheritFrom to recursively resolve ITypeParameterSymbol constraints - Include cycle-safe traversal over constraint types to prevent infinite loops - Refactor UseEventHandlerOfTAnalyzer to use the centralized behavior instead of local constraint recursion - Simplify IsOrImplements implementation by delegating to Implements - Add regression test for generic type parameter constraints in EventsShouldHaveProperArgumentsAnalyzerTests - Update MA0046 and MA0093 documentation to note generic constraint support This ensures all analyzers that use these helpers consistently handle generic type parameters, preventing false positives and negatives across the codebase. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 24, 2026
Closed
Closed
Closed
Closed
Bump Meziantou.Analyzer from 3.0.103 to 3.0.113
Analogy-LogViewer/Analogy.LogViewer.OpenTelemetry#53
Closed
Closed
Closed
pkloehn1
added a commit
to paragon-stats/paragon-stats
that referenced
this pull request
Jun 25, 2026
Updated [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 3.0.108 to 3.0.113. <details> <summary>Release notes</summary> _Sourced from [Meziantou.Analyzer's releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._ ## 3.0.113 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.113> ## What's Changed * Add global generic constraint support to type relationship helpers by @meziantou in meziantou/Meziantou.Analyzer#1199 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.112...3.0.113 ## 3.0.112 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.112> **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.111...3.0.112 ## 3.0.111 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.111> ## What's Changed * Fix MA0206 for documented class declarations by @meziantou in meziantou/Meziantou.Analyzer#1198 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.110...3.0.111 ## 3.0.110 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.110> ## What's Changed * MA0204: exclude WPF XAML root types from unnecessary `partial` diagnostics by @meziantou with @Copilot in meziantou/Meziantou.Analyzer#1195 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.109...3.0.110 ## 3.0.109 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.109> ## What's Changed * Add MA0207/MA0208 for FixedAddressValueTypeAttribute validation by @meziantou in meziantou/Meziantou.Analyzer#1193 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.108...3.0.109 Commits viewable in [compare view](meziantou/Meziantou.Analyzer@3.0.108...3.0.113). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details>
This was referenced Jun 25, 2026
Open
This was referenced Jun 26, 2026
Bump Meziantou.Analyzer from 3.0.103 to 3.0.115
Analogy-LogViewer/Analogy.LogViewer.OpenTelemetry#56
Open
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.
Motivation
MA0046 (Use EventHandler to declare events) recently added support for generic type parameter constraints, but this capability was isolated to a single analyzer. Other relationship-checking helpers like
IsOrInheritFrom,Implements, andInheritsFromlack this awareness, causing them to miss or incorrectly handle cases where a type parameter is constrained to a base type or interface. This creates inconsistency across the codebase and false positives/negatives in analyzers that rely on these helpers.Approach
Centralized generic constraint resolution: Updated all type relationship helpers in
TypeSymbolExtensionsto recursively resolve generic type parameter constraints:InheritsFrom– now checks if constraint types inherit from the targetImplements– now checks if constraint types implement the target interfaceImplementsGenericInterface– now checks generic interface constraintsIsOrImplements– simplified by delegating toImplementsIsOrInheritFrom– combined type equality check with constraint resolutionCycle-safe recursion: Added
AnyConstraintTypeMatcheshelper that tracks visited type parameters using a HashSet to prevent infinite loops in recursive constraint chains.Refactored consumers: Simplified
UseEventHandlerOfTAnalyzer(MA0046) to useIsOrInheritFromdirectly instead of maintaining its own constraint-traversal logic.Changes
TypeSymbolExtensions.cs: Added generic constraint awareness to five core helpers; introduced cycle-safe traversalUseEventHandlerOfTAnalyzer.cs: Removed local constraint recursion (14 lines → 2 lines)EventsShouldHaveProperArgumentsAnalyzerTests.cs: Added regression test for constrained generic delegate argumentsdocs/Rules/MA0046.mdanddocs/Rules/MA0093.md: Updated to note generic constraint supportTesting
EventsShouldHaveProperArgumentsAnalyzercorrectly flags null EventArgs on constrained generic delegates