Static Method Code Action: Listing 2

Full GetEdit Method Implementation

Listing 2: StaticMethodCodeAction GetEdit Function
 public ICodeActionEdit GetEdit(System.Threading.CancellationToken cancellationT
    var syntaxTree = (SyntaxTree)_document.GetSyntaxTree(cancellationToken);

    var firstToken = _methodDeclaration.GetFirstToken();
    var firstTokenTrivia = firstToken.LeadingTrivia;

    var formattedMethodDeclaration = _methodDeclaration.ReplaceToken(
        firstToken, firstToken.WithLeadingTrivia(Syntax.TriviaList()));

    var staticToken = Syntax.Token(firstTokenTrivia, SyntaxKind.StaticKeyword);

    var newModifiers = Syntax.TokenList(
        new[] { staticToken }.Concat(formattedMethodDeclaration.Modifiers));

    var newMethodDeclaration = formattedMethodDeclaration.Update(
    var formattedLocalDeclaration = CodeActionAnnotations.FormattingAnnotation

    var tree = (SyntaxTree)_document.GetSyntaxTree();
    var newRoot = tree.Root.ReplaceNode(_methodDeclaration,

    return _editFactory.CreateTreeTransformEdit(_document.Project.Solution,
        syntaxTree, newRoot, cancellationToken: cancellationToken);

About the Author

Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at [email protected].

comments powered by Disqus


  • .NET for Apache Spark Debuts in Version 1.0

    The open source project .NET for Apache Spark has debuted in version 1.0, finally vaulting the C# and F# programming languages into Big Data first-class citizenship.

  • In-App Reviews Come to Xamarin.Forms Android

    Android is playing a little catch-up to iOS regarding in-app review functionality, just now coming tp Microsoft's Xamarin.Forms implementation.

  • C# Slides in Usage Ranking of Programming Languages

    "The fact that C# lost three places in the ranking of language communities during the last three years is mostly explained by its slower growth compared to C/C++ and PHP."

  • Telerik UI for Blazor Updated

    Progress announced an update to its Telerik UI for Blazor components, targeting Microsoft's open source Blazor framework that lets C# coders create web apps without having to rely upon JavaScript.

  • Infragistics Unveils UI Components for Blazor

    Infragistics, specializing in third-party UI/UX controls and tools, unveiled a new offering targeting Blazor, Microsoft's red-hot open source framework that allows for C#-based web development instead of traditional mainstay JavaScript.

Upcoming Events