Skip to content

[API Proposal]: Expose SymbolAnnotation.Create #65041

@Youssef1313

Description

@Youssef1313

Background and Motivation

Codefixes can usually annotate a TypeSyntax with AddImportsAnnotation so that the using directive is added automatically if not present. However, when the codefix suggests using an extension method, AddImportsAnnotation alone cannot work.

Proposed API

namespace Microsoft.CodeAnalysis.Simplification
{
-    internal class SymbolAnnotation
+    public class SymbolAnnotation
     {
         // Make everything internal except Create(ISymbol symbol) method
     }
}

Usage Examples

var annotation = SymbolAnnotation.Create(compilation.GetTypeByMetadataName("MyNamespace.Extensions"));
return document.WithSyntaxRoot(
    root.ReplaceNode(nodetoReplace, extensionInvocation.WithAdditionalAnnotations(Simplifier.AddImportsAnnotation, annotation)));

Alternative Designs

Risks

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions