Spaces:
Sleeping
Sleeping
File size: 1,203 Bytes
1ae2e8e |
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 37 38 39 40 41 |
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
namespace RobloxCS
{
public abstract class BaseTransformer : CSharpSyntaxRewriter
{
protected SyntaxNode _root;
protected readonly SyntaxTree _tree;
protected readonly ConfigData _config;
public BaseTransformer(SyntaxTree tree, ConfigData config)
{
_root = tree.GetRoot();
_tree = tree;
_config = config;
}
public SyntaxTree TransformTree()
{
return _tree.WithRootAndOptions(Visit(_root), _tree.Options);
}
protected string? TryGetName(SyntaxNode node)
{
return Utility.GetNamesFromNode(node).FirstOrDefault();
}
protected string GetName(SyntaxNode node)
{
return Utility.GetNamesFromNode(node).First();
}
protected SyntaxToken CreateIdentifierToken(string text, string? valueText = null, SyntaxTriviaList? trivia = null)
{
var triviaList = trivia ?? SyntaxFactory.TriviaList();
return SyntaxFactory.VerbatimIdentifier(triviaList, text, valueText ?? text, triviaList);
}
}
}
|