Skip to content

Seal member if possible #372

@giggio

Description

@giggio

This is just like #371, but applies to methods that are virtual and inherited from a base class.

class Base
{
    public virtual void Foo() { }
}
class C : Base
{
    public override void Foo() { }
}

Becomes:

class Base
{
    public virtual void Foo() { }
}
class C : Base
{
    public override sealed void Foo() { }
}

An analysis has to be made if the method can me made virtual. The analyzer has to check if there is derived class, and if in those classes if there is an override of the method.

Category: Performance
Diagnostic Id: CC0094
Severity: Hidden

Due to the problems on #293 this is the suggested strategy for this issue:

  1. Offer the diagnostic on the class declaration only, not anywhere else. It is a simple marker/hidden diagnostic, no further analysis needed.
  2. The analysis is completed on the code fix provider. It checks, asynchronously, if there are classes overriding that member. If not, the code fix is offer. Otherwise it is not.

It has to check for cancellation frequently, as this analysis made on the code fix provider will be costly.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions