本文整理汇总了C#中MemberDeclarationSyntax.WithModifiers方法的典型用法代码示例。如果您正苦于以下问题:C# MemberDeclarationSyntax.WithModifiers方法的具体用法?C# MemberDeclarationSyntax.WithModifiers怎么用?C# MemberDeclarationSyntax.WithModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemberDeclarationSyntax
的用法示例。
在下文中一共展示了MemberDeclarationSyntax.WithModifiers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveLeadingTriviasFromFirstDeclarationModifier
private static MemberDeclarationSyntax RemoveLeadingTriviasFromFirstDeclarationModifier(MemberDeclarationSyntax declaration, SyntaxTokenList modifiers, SyntaxToken modifier) => declaration.WithModifiers(modifiers.Replace(modifier, modifier.WithLeadingTrivia(default(SyntaxTriviaList))));
示例2: ReplaceDeclarationModifiers
private static MemberDeclarationSyntax ReplaceDeclarationModifiers(MemberDeclarationSyntax declaration, List<SyntaxToken> oldAccessibilityModifiers, SyntaxTokenList newAccessibilityModifiers)
{
var result = declaration;
var replacedModifiers = declaration.GetModifiers();
if (oldAccessibilityModifiers.Count == 0)
{
replacedModifiers = replacedModifiers.InsertRange(0,newAccessibilityModifiers);
}
else if(oldAccessibilityModifiers.Count == 1)
{
replacedModifiers = replacedModifiers.ReplaceRange(oldAccessibilityModifiers[0], newAccessibilityModifiers);
}
else if(oldAccessibilityModifiers.Count == 2)
{
replacedModifiers = replacedModifiers.ReplaceRange(oldAccessibilityModifiers[0], newAccessibilityModifiers);
replacedModifiers = replacedModifiers.Remove(replacedModifiers.SingleOrDefault(token => token.IsKind(oldAccessibilityModifiers[1].Kind())));
}
result = declaration.WithModifiers(replacedModifiers);
return result;
}
示例3: UpdateSyntaxRoot
private static SyntaxNode UpdateSyntaxRoot(MemberDeclarationSyntax memberDeclaration, SyntaxTokenList newModifiers, SyntaxNode syntaxRoot)
{
var newDeclaration = memberDeclaration.WithModifiers(newModifiers);
return syntaxRoot.ReplaceNode(memberDeclaration, newDeclaration);
}