本文整理汇总了C#中SyntaxNode.GetBracePair方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.GetBracePair方法的具体用法?C# SyntaxNode.GetBracePair怎么用?C# SyntaxNode.GetBracePair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.GetBracePair方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAlignTokensOperations
public override void AddAlignTokensOperations(List<AlignTokensOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<AlignTokensOperation> nextOperation)
{
nextOperation.Invoke(list);
var syntaxNode = node;
var bracePair = node.GetBracePair();
if (!bracePair.IsValidBracePair())
{
return;
}
if (syntaxNode.IsLambdaBodyBlock() ||
node is InitializerExpressionSyntax)
{
AddAlignIndentationOfTokensToFirstTokenOfBaseTokenLineOperation(list, syntaxNode, bracePair.Item1, SpecializedCollections.SingletonEnumerable((SyntaxToken)bracePair.Item2));
}
}
示例2: AddIndentBlockOperations
public override void AddIndentBlockOperations(List<IndentBlockOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<IndentBlockOperation> nextOperation)
{
nextOperation.Invoke(list);
var bracePair = node.GetBracePair();
// don't put block indentation operation if the block only contains lambda expression body block
if (node.IsLambdaBodyBlock() || !bracePair.IsValidBracePair())
{
return;
}
if (optionSet.GetOption(CSharpFormattingOptions.OpenCloseBracesIndent))
{
AddIndentBlockOperation(list, bracePair.Item1, bracePair.Item1, bracePair.Item1.Span);
AddIndentBlockOperation(list, bracePair.Item2, bracePair.Item2, bracePair.Item2.Span);
}
}
示例3: AddAlignTokensOperations
public override void AddAlignTokensOperations(List<AlignTokensOperation> list, SyntaxNode node, OptionSet optionSet, NextAction<AlignTokensOperation> nextOperation)
{
base.AddAlignTokensOperations(list, node, optionSet, nextOperation);
if (optionSet.GetOption(SmartIndent, node.Language) == IndentStyle.Block)
{
var bracePair = node.GetBracePair();
if (bracePair.IsValidBracePair())
{
AddAlignIndentationOfTokensToBaseTokenOperation(list, node, bracePair.Item1, SpecializedCollections.SingletonEnumerable(bracePair.Item2), AlignTokensOption.AlignIndentationOfTokensToFirstTokenOfBaseTokenLine);
}
}
}
示例4: AddBraceSuppressOperations
private void AddBraceSuppressOperations(List<SuppressOperation> list, SyntaxNode node)
{
var bracePair = node.GetBracePair();
if (!bracePair.IsValidBracePair())
{
return;
}
var firstTokenOfNode = node.GetFirstToken(includeZeroWidth: true);
if (node.IsLambdaBodyBlock())
{
// include lambda itself.
firstTokenOfNode = node.Parent.GetFirstToken(includeZeroWidth: true);
}
// suppress wrapping on whole construct that owns braces and also brace pair itself if it is on same line
AddSuppressWrappingIfOnSingleLineOperation(list, firstTokenOfNode, bracePair.Item2);
AddSuppressWrappingIfOnSingleLineOperation(list, bracePair.Item1, bracePair.Item2);
}
示例5: AddBlockIndentationOperation
private void AddBlockIndentationOperation(List<IndentBlockOperation> list, SyntaxNode node, OptionSet optionSet)
{
var bracePair = node.GetBracePair();
// don't put block indentation operation if the block only contains label statement
if (!bracePair.IsValidBracePair())
{
return;
}
// for lambda, set alignment around braces so that users can put brace wherever they want
if (node.IsLambdaBodyBlock() || node.IsAnonymousMethodBlock())
{
AddAlignmentBlockOperationRelativeToFirstTokenOnBaseTokenLine(list, bracePair);
}
// For ArrayInitializationExpression, set indent to relative to the open brace so the content is properly indented
if (node.IsKind(SyntaxKind.ArrayInitializerExpression) && node.Parent != null && node.Parent.IsKind(SyntaxKind.ArrayCreationExpression))
{
AddAlignmentBlockOperationRelativeToFirstTokenOnBaseTokenLine(list, bracePair);
}
if (node is BlockSyntax && !optionSet.GetOption(CSharpFormattingOptions.IndentBlock))
{
// do not add indent operation for block
return;
}
if (node is SwitchStatementSyntax && !optionSet.GetOption(CSharpFormattingOptions.IndentSwitchSection))
{
// do not add indent operation for switch statement
return;
}
AddIndentBlockOperation(list, bracePair.Item1.GetNextToken(includeZeroWidth: true), bracePair.Item2.GetPreviousToken(includeZeroWidth: true));
}
示例6: AddBlockIndentationOperation
private void AddBlockIndentationOperation(List<IndentBlockOperation> list, SyntaxNode node, OptionSet optionSet)
{
var bracePair = node.GetBracePair();
// don't put block indentation operation if the block only contains label statement
if (!bracePair.IsValidBracePair())
{
return;
}
// for lambda, set alignment around braces so that users can put brace wherever they want
if (node.IsLambdaBodyBlock() || node.IsAnonymousMethodBlock())
{
var option = IndentBlockOption.RelativeToFirstTokenOnBaseTokenLine;
SetAlignmentBlockOperation(list, bracePair.Item1, bracePair.Item1.GetNextToken(includeZeroWidth: true), bracePair.Item2, option);
}
if (node is BlockSyntax && !optionSet.GetOption(CSharpFormattingOptions.IndentBlock))
{
// do not add indent operation for block
return;
}
if (node is SwitchStatementSyntax && !optionSet.GetOption(CSharpFormattingOptions.IndentSwitchSection))
{
// do not add indent operation for switch statement
return;
}
AddIndentBlockOperation(list, bracePair.Item1.GetNextToken(includeZeroWidth: true), bracePair.Item2.GetPreviousToken(includeZeroWidth: true));
}
示例7: AddBlockIndentationOperation
private void AddBlockIndentationOperation(List<IndentBlockOperation> list, SyntaxNode node, OptionSet optionSet)
{
var bracePair = node.GetBracePair();
// don't put block indentation operation if the block only contains label statement
if (!bracePair.IsValidBracePair())
{
return;
}
if (IsExpressionWithBraces(node))
{
var option = IndentBlockOption.RelativePosition;
if (node.IsLambdaBodyBlock() || node is InitializerExpressionSyntax)
{
option = IndentBlockOption.RelativeToFirstTokenOnBaseTokenLine;
}
AddIndentBlockOperation(list, GetBaseTokenForRelativeIndentation(node, bracePair.Item1, optionSet),
bracePair.Item1.GetNextToken(includeZeroWidth: true), bracePair.Item2.GetPreviousToken(includeZeroWidth: true), option);
return;
}
if (node is BlockSyntax && !optionSet.GetOption(CSharpFormattingOptions.IndentBlock))
{
// do not add indent operation for block
return;
}
if (node is SwitchStatementSyntax && !optionSet.GetOption(CSharpFormattingOptions.IndentSwitchSection))
{
// do not add indent operation for switch statement
return;
}
AddIndentBlockOperation(list, bracePair.Item1.GetNextToken(includeZeroWidth: true), bracePair.Item2.GetPreviousToken(includeZeroWidth: true));
}