本文整理汇总了C#中Microsoft.CodeAnalysis.Text.SourceText.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# SourceText.Replace方法的具体用法?C# SourceText.Replace怎么用?C# SourceText.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Text.SourceText
的用法示例。
在下文中一共展示了SourceText.Replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddSymbolNamesToSourceText
private static SourceText AddSymbolNamesToSourceText(SourceText sourceText, IEnumerable<string> newSymbolNames)
{
HashSet<string> lines = GetLinesFromSourceText(sourceText);
foreach (var name in newSymbolNames)
{
lines.Add(name);
}
var sortedLines = lines.OrderBy(s => s, StringComparer.Ordinal);
var newSourceText = sourceText.Replace(new TextSpan(0, sourceText.Length), string.Join(Environment.NewLine, sortedLines));
return newSourceText;
}
示例2: RemoveSymbolNamesFromSourceText
private static SourceText RemoveSymbolNamesFromSourceText(SourceText sourceText, ImmutableHashSet<string> linesToRemove)
{
if (linesToRemove.IsEmpty)
{
return sourceText;
}
HashSet<string> lines = GetLinesFromSourceText(sourceText);
var newLines = lines.Where(line => !linesToRemove.Contains(line));
IOrderedEnumerable<string> sortedLines = newLines.OrderBy(s => s, StringComparer.Ordinal);
SourceText newSourceText = sourceText.Replace(new TextSpan(0, sourceText.Length), string.Join(Environment.NewLine, sortedLines));
return newSourceText;
}