本文整理汇总了C#中Microsoft.CodeAnalysis.SyntaxTree.WithFilePath方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTree.WithFilePath方法的具体用法?C# SyntaxTree.WithFilePath怎么用?C# SyntaxTree.WithFilePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SyntaxTree
的用法示例。
在下文中一共展示了SyntaxTree.WithFilePath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Normalize
/// <summary>
/// Normalizes the <paramref name="syntaxTree" /> of the <see cref="Compilation" />.
/// </summary>
/// <param name="syntaxTree">The syntax tree that should be normalized.</param>
protected override SyntaxTree Normalize(SyntaxTree syntaxTree)
{
var root = syntaxTree.GetRoot();
var firstNode = root.GetFirstToken(true, true, true, true).Parent;
var updatedNode = firstNode.PrependLineDirective(1, syntaxTree.FilePath);
return syntaxTree.WithFilePath(syntaxTree.FilePath + Guid.NewGuid()).WithRoot(root.ReplaceNode(firstNode, updatedNode));
}
示例2: ToResult
private static SyntaxTree ToResult(Compilation compilation, string name, SyntaxTree tree, string path, bool writeToDisk)
{
var ext = (compilation.Language == LanguageNames.VisualBasic) ? ".vb" : ".cs";
var fileName = $"{FixUpName(name)}{ext}";
path = PathUtilities.CombinePossiblyRelativeAndRelativePaths(path, fileName);
if (writeToDisk)
{
var sourceText = tree.GetText();
var encoding = sourceText.Encoding ?? Encoding.UTF8;
PortableShim.File.WriteAllText(path, sourceText.ToString(), encoding);
}
return tree.WithFilePath(path);
}