Skip to content
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

Implement S4060 - Avoid unsealed attributes - for VB.NET #5930

Closed
pavel-mikula-sonarsource opened this issue Jul 29, 2022 · 1 comment · Fixed by #5728
Closed

Implement S4060 - Avoid unsealed attributes - for VB.NET #5930

pavel-mikula-sonarsource opened this issue Jul 29, 2022 · 1 comment · Fixed by #5728
Assignees
Labels
Area: VB.NET VB.NET rules related issues.
Milestone

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

pavel-mikula-sonarsource commented Jul 29, 2022

See S4060

Description

The .NET framework class library provides methods for retrieving custom attributes. Sealing the attribute eliminates the search through the inheritance hierarchy, and can improve performance.

This rule raises an issue when a public type inherits from System.Attribute, is not abstract, and is not sealed.

Noncompliant Code Example

Namespace MyLibrary 

    <AttributeUsage(AttributeTargets.Class)>
    Public Class MyAttribute ' Noncompliant
        Inherits Attribute 
    
        Public Sub New(name as String) 
            Value = val
        End Sub
        
        Public Readonly Property Value as String
    End Class
End Namespace

Compliant Solution

Namespace MyLibrary 

    <AttributeUsage(AttributeTargets.Class)>
    Public MustInherit Class MyAttribute ' Noncompliant
        Inherits Attribute 
    
        Public Sub New(val as String) 
            Value = val 
        End Sub
        
        Public Readonly Property Value as String
    End Class
End Namespace
@pavel-mikula-sonarsource
Copy link
Contributor Author

Implemented in #5728

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: VB.NET VB.NET rules related issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant