forked from nhabuiduc/TypescriptSyntaxPaste
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAddIPrefixInterfaceDeclaration.cs
More file actions
36 lines (32 loc) · 1.21 KB
/
AddIPrefixInterfaceDeclaration.cs
File metadata and controls
36 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Copyright (c) 2019-2021 João Pedro Martins Neves (shivayl) - All Rights Reserved.
*
* CSharpToTypescript is licensed under the GPLv3.0 license (GNU General Public License v3.0),
* located in the root of this project, under the name "LICENSE.md".
*
*/
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace CSharpToTypescript
{
public class AddIPrefixInterfaceDeclaration
{
class AddIPrefixInterfaceDeclarationRewriter : CSharpSyntaxRewriter
{
public override SyntaxNode VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
{
var name = node.Identifier.ValueText;
if (name.StartsWith( "I" ))
{
return base.VisitInterfaceDeclaration( node );
}
return node.ReplaceToken( node.Identifier, SyntaxFactory.ParseToken( "I" + name ) );
}
}
public static CSharpSyntaxNode AddIPrefix(CSharpSyntaxNode syntaxNode)
{
return (CSharpSyntaxNode)new AddIPrefixInterfaceDeclarationRewriter().Visit( syntaxNode );
}
}
}