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

New Rule Idea: Replace protected parameterless empty constructor with abstract class #8796

Open
pavel-mikula-sonarsource opened this issue Feb 22, 2024 · 2 comments
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: Rule Idea Idea for a rule that has NOT been specified.

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

Follow up of #8795

Suggest the exact opposite from what was originally suggested: If there's a parameterless protected constructor without any public/internal constructors, suggest making the class abstract to make the contract clear.

Ask to remove the constructor only if it's empty.

@pavel-mikula-sonarsource pavel-mikula-sonarsource added Type: Rule Idea Idea for a rule that has NOT been specified. Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. labels Feb 22, 2024
@Tim-Pohlmann
Copy link
Contributor

This would also trigger in a case like this, right?

class MyClass
{
    protected MyClass()
    {
    }
    
    public MyClass Factory()
    {
        return new MyClass();
        // do some setup
    }
}

I think there needs to be another condition.

@pavel-mikula-sonarsource
Copy link
Contributor Author

Maybe not instantiated inside as well... Does such a thing have a reason not to be sealed?

@antonioaversa antonioaversa changed the title Rule idea: Replace protected parameterless empty constructor with abstract class New Rule Idea: Replace protected parameterless empty constructor with abstract class Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: Rule Idea Idea for a rule that has NOT been specified.
Projects
None yet
Development

No branches or pull requests

2 participants