本文整理汇总了C#中SyntaxNode.IsLambdaBodyBlock方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.IsLambdaBodyBlock方法的具体用法?C# SyntaxNode.IsLambdaBodyBlock怎么用?C# SyntaxNode.IsLambdaBodyBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.IsLambdaBodyBlock方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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);
}
示例3: 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));
}
示例4: 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));
}
示例5: IsExpressionWithBraces
private bool IsExpressionWithBraces(SyntaxNode node)
{
return node.IsLambdaBodyBlock() ||
node is AnonymousObjectCreationExpressionSyntax ||
node is AnonymousMethodExpressionSyntax ||
node is InitializerExpressionSyntax;
}
示例6: GetBaseTokenForRelativeIndentation
private SyntaxToken GetBaseTokenForRelativeIndentation(SyntaxNode node, SyntaxToken openingBrace, OptionSet optionSet)
{
var useBrace = node.IsLambdaBodyBlock() ||
node is InitializerExpressionSyntax ||
(node is AnonymousObjectCreationExpressionSyntax && optionSet.GetOption(CSharpFormattingOptions.OpenBracesInNewLineForAnonymousType)) ||
(node is AnonymousMethodExpressionSyntax && optionSet.GetOption(CSharpFormattingOptions.OpenBracesInNewLineForAnonymousMethods));
if (useBrace)
{
return openingBrace;
}
return GetFirstTokenFromContainingStatement(openingBrace);
}
示例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));
}