Open sandboxFocusImprove this doc

Namespace Metalama.Framework.CodeFixes

This namespace enables you to suggest code fixes and code refactorings, which are changes to source code that appear in the lightbulb or screwdriver menu of your IDE.

You can instantiate code fixes using the static methods of the CodeFixFactory class.

To add code fixes to a diagnostic, utilize the IDiagnostic.WithCodeFixes method.

To suggest a code refactoring without reporting a diagnostic, employ the Suggesttext=ScopedDiagnosticSink.Suggest> method.

Class diagram

classDiagram

    class ScopedDiagnosticSink {
        Report()
        Suppress()
        Suggest()
    }

    class IDiagnostic {
        CodeFixes
        WithCodeFixes(CodeFixes[])
    }

  class CodeFix {
        Id
        Title
    }
    class CodeFixFactory {
        ApplyAspect()$
        AddAttribute()$
        RemoteAttribute()$
        CreateCustomCodeFix(Func~ICodeFixBuilder,Task~)$
    }
    class ICodeFixBuilder {
       ApplyAspectAsync()
       AddAttributeAsync()
       RemoteAttributeAsync()
    }

    ICodeFixBuilder <-- CodeFixFactory : custom code fixes\nimplemented with
    CodeFix <-- CodeFixFactory : creates
    IDiagnostic <-- CodeFix: add to
    ScopedDiagnosticSink <-- CodeFix: suggest to
    ScopedDiagnosticSink <-- IDiagnostic: reports to

Namespace members

Classes

CodeFix

Represents a modification of the current solution, including the Title of transformation. To instantiate a single-step code fix, use CodeFixFactory. To instantiate a more complex code fix, use the constructor.

CodeFixFactory

Creates instances of the CodeFix class.

Interfaces

ICodeActionBuilder

Argument of the delegate passed to CodeFix constructor. Exposes methods that allow to modify the current solution.

ICodeActionContext

Gets the context in which a code action executes. Exposed by ICodeActionBuilder. If you implement your own code action using the Metalama SDK, you should cast this interface to ISdkCodeActionContext.