本文整理汇总了C#中SyntaxTokenList.Where方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTokenList.Where方法的具体用法?C# SyntaxTokenList.Where怎么用?C# SyntaxTokenList.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxTokenList
的用法示例。
在下文中一共展示了SyntaxTokenList.Where方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PartiallySortModifiers
/// <summary>
/// Sorts the modifier list to fix all issues before <paramref name="modifierToFix"/>
/// and keep the remaining modifiers untouched.
/// The trivia will be maintained positionally.
/// The relative order within the different kinds <seealso cref="ModifierType"/> will not be
/// changed.
/// </summary>
/// <param name="modifiers">All modifiers from the declaration.</param>
/// <param name="modifierToFix">The modifier with diagnostics.</param>
/// <returns>A partially sorted modifier list (sorted up to <paramref name="modifierToFix"/>)</returns>
private static SyntaxTokenList PartiallySortModifiers(SyntaxTokenList modifiers, SyntaxToken modifierToFix)
{
var accessModifiers = modifiers.Where(modifier => GetModifierType(modifier) == ModifierType.Access);
var staticModifiers = modifiers.Where(modifier => GetModifierType(modifier) == ModifierType.Static);
var otherModifiers = modifiers.Where(modifier => GetModifierType(modifier) == ModifierType.Other);
IEnumerable<SyntaxToken> beforeIncluding;
// the modifier to fix is of type other, so we need to sort the whole list of
// modifier list
if (GetModifierType(modifierToFix) == ModifierType.Other)
{
beforeIncluding = accessModifiers
.Concat(staticModifiers)
.Concat(otherModifiers);
}
else if (GetModifierType(modifierToFix) == ModifierType.Static)
{
beforeIncluding = accessModifiers
.Concat(staticModifiers.TakeWhile(modifier => modifier != modifierToFix))
.Concat(new[] { modifierToFix });
}
else
{
beforeIncluding = accessModifiers
.TakeWhile(modifier => modifier != modifierToFix)
.Concat(new[] { modifierToFix });
}
var after = modifiers.Where(modifier => !beforeIncluding.Contains(modifier));
return AdjustTrivia(beforeIncluding.Concat(after), modifiers);
}
示例2: FullySortModifiers
/// <summary>
/// Sorts the complete modifier list to fix all issues.
/// The trivia will be maintained positionally.
/// The relative order within the different kinds <seealso cref="ModifierType"/> will not be
/// changed.
/// </summary>
/// <param name="modifiers">All modifiers from the declaration.</param>
/// <returns>A fully sorted modifier list.</returns>
private static SyntaxTokenList FullySortModifiers(SyntaxTokenList modifiers)
{
var accessModifiers = modifiers.Where(modifier => GetModifierType(modifier) == ModifierType.Access);
var staticModifiers = modifiers.Where(modifier => GetModifierType(modifier) == ModifierType.Static);
var otherModifiers = modifiers.Where(modifier => GetModifierType(modifier) == ModifierType.Other);
return AdjustTrivia(
accessModifiers
.Concat(staticModifiers)
.Concat(otherModifiers), modifiers);
}
示例3: RemoveModifier
private static SyntaxTokenList RemoveModifier(SyntaxTokenList list, params SyntaxKind[] modifiers)
{
return SyntaxFactory.TokenList(list.Where(t => Array.IndexOf(modifiers, t.Kind()) < 0));
}