-
-
Notifications
You must be signed in to change notification settings - Fork 84
Fix analyzer to skip required keyword enforcement for Attribute class properties #2981
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
Merged
Conversation
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
… properties Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
required
keyword for injected properties in Attribute classes
Copilot finished work on behalf of
thomhurst
August 21, 2025 13:05
This was referenced Aug 21, 2025
This was referenced Aug 25, 2025
Merged
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.
The TUnit analyzer was incorrectly enforcing the
required
keyword for properties with data source attributes in all classes, including custom Attribute classes. This caused unnecessary compiler errors when creating custom attributes that use property injection.Problem
When defining a custom attribute that inherits from
System.Attribute
with injected properties, the analyzer would flag TUnit0043 errors:This was problematic because:
required
keyword enforcement should only apply to test classes where property injection occurs during test executionSolution
Modified the
TestDataAnalyzer.CheckPropertyAccessor()
method to:Check inheritance hierarchy: Added
IsInAttributeClass()
helper method that uses the existingIsOrInherits()
extension to detect if a property's containing type inherits fromSystem.Attribute
Skip enforcement for Attribute classes: When a property with data source attributes is in an Attribute class, the analyzer no longer reports TUnit0043
Maintain enforcement for test classes: Regular test classes continue to require the
required
keyword for proper property injectionAfter the fix
The fix correctly handles both direct inheritance (
: System.Attribute
) and indirect inheritance through base classes, ensuring robust detection of attribute classes.Fixes #2980.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.