public static ClassDeclarationSyntax AddConstructor(this ClassDeclarationSyntax currentClass) { var identifer = currentClass.DescendantTokens() .First(t => t.IsKind(SyntaxKind.IdentifierToken) && t.Parent.Kind() == SyntaxKind.ClassDeclaration); var constructorBase = "public " + identifer.Text + "(){}"; var methodSyntax = CSharpSyntaxTree.ParseText(constructorBase); var method = methodSyntax.GetRoot().DescendantNodes().OfType <MethodDeclarationSyntax>().First(); currentClass = currentClass.AddMembers(method); return(currentClass);//.(methodSyntax.GetRoot().SyntaxTree;); }