Skip to content

Instantly share code, notes, and snippets.

@JoshVarty
Created August 15, 2014 23:59
Show Gist options
  • Save JoshVarty/694447a0b1f6f576adfc to your computer and use it in GitHub Desktop.
Save JoshVarty/694447a0b1f6f576adfc to your computer and use it in GitHub Desktop.
public class EmtpyStatementRemoval : CSharpSyntaxRewriter
{
public override SyntaxNode VisitEmptyStatement(EmptyStatementSyntax node)
{
//Simply remove all Empty Statements
return null;
}
}
public static void Main(string[] args)
{
//A syntax tree with an unnecessary semicolon on its own line
var tree = CSharpSyntaxTree.ParseText(@"
public class Sample
{
public void Foo()
{
Console.WriteLine();
;
}
}");
var rewriter = new EmtpyStatementRemoval();
var result = rewriter.Visit(tree.GetRoot());
Console.WriteLine(result.ToFullString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment