Created
June 11, 2012 17:59
-
-
Save DinisCruz/2911643 to your computer and use it in GitHub Desktop.
O2 Script - Refactored Roslyn 'AddingMethodToClass' method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var code = @" | |
class C | |
{ | |
}"; | |
// Get ClassDeclarationSyntax corresponding to 'class C' above. | |
var classDeclaration = code.astTree() | |
.compilationUnit() | |
.classes().first(); | |
// Construct a new MethodDeclarationSyntax. | |
// Add this new MethodDeclarationSyntax to the above ClassDeclarationSyntax. | |
var newClassDeclaration = classDeclaration.add("M".methodDeclaration()); | |
// Update the CompilationUnitSyntax with the new ClassDeclarationSyntax. | |
// Format the new CompilationUnitSyntax. | |
return classDeclaration.replaceWith(newClassDeclaration).formatedCode(); | |
//O2Ref:O2_FluentSharp_Roslyn.dll | |
//O2File:_Extra_methods_Roslyn_API.cs | |
//O2Ref:O2_FluentSharp_Roslyn.dll | |
//O2Ref:Roslyn.Services.dll | |
//O2Ref:Roslyn.Compilers.dll | |
//O2Ref:Roslyn.Compilers.CSharp.dll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment