All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S4060.html Maven / Gradle / Ivy

There is a newer version: 9.32.0.97167
Show newest version

Why is this an issue?

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

using System;

public class MyAttribute: Attribute // Noncompliant
{
    public string Name { get; }

    public MyAttribute(string name) =>
        Name = name;
}

Compliant solution

using System;

public sealed class MyAttribute : Attribute
{
    public string Name { get; }

    public MyAttribute(string name) =>
        Name = name;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy