本文整理汇总了C#中Microsoft.CodeAnalysis.SyntaxNode.IsLambdaBodyBlock方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.IsLambdaBodyBlock方法的具体用法?C# SyntaxNode.IsLambdaBodyBlock怎么用?C# SyntaxNode.IsLambdaBodyBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.IsLambdaBodyBlock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBraceSuppressOperations
protected void AddBraceSuppressOperations(List<SuppressOperation> list, SyntaxNode node, SyntaxToken lastToken)
{
var bracePair = node.GetBracePair();
if (!bracePair.IsValidBracePair())
{
return;
}
var firstTokenOfNode = node.GetFirstToken(includeZeroWidth: true);
var memberDeclNode = node as MemberDeclarationSyntax;
if (memberDeclNode != null)
{
var firstAndLastTokens = memberDeclNode.GetFirstAndLastMemberDeclarationTokensAfterAttributes();
firstTokenOfNode = firstAndLastTokens.Item1;
}
if (node.IsLambdaBodyBlock())
{
// include lambda itself.
firstTokenOfNode = node.Parent.GetFirstToken(includeZeroWidth: true);
}
// We may think we have a complete set of braces, but that may not actually be the case
// due incomplete code. i.e. we have something like:
//
// class C
// {
// int Blah {
// get { return blah
// }
//
// In this case the parse will think that the get-accessor is actually on two lines
// (because it will consume the close curly that more accurately belongs to the class.
//
// Now there are different behaviors we want depending on what the user is doing
// and what we are formatting. For example, if the user hits semicolon at the end of
// "blah", then we want to keep the accessor on a single line. In this scenario we
// effectively want to ignore the following close curly as it may not be important to
// this construct in the mind of the user.
//
// However, say the user hits semicolon, then hits enter, then types a close curly.
// In this scenario we would actually want the get-accessor to be formatted over multiple
// lines. The difference here is that because the user just hit close-curly here we can
// consider it as being part of the closest construct and we can consider its placement
// when deciding if the construct is on a single line.
var endToken = bracePair.Item2;
if (lastToken.Kind() != SyntaxKind.CloseBraceToken &&
lastToken.Kind() != SyntaxKind.EndOfFileToken &&
!endToken.IsMissing)
{
// The user didn't just type the close brace. So any close brace we have may
// actually belong to a containing construct. See if any containers are missing
// a close brace, and if so, act as if our own close brace is missing.
if (SomeParentHasMissingCloseBrace(node.Parent))
{
if (node.IsKind(SyntaxKind.Block) && ((BlockSyntax)node).Statements.Count >= 1)
{
// In the case of a block, see if the first statement is on the same line
// as the open curly. If so then we'll want to consider the end of the
// block as the end of the first statement. i.e. if you have:
//
// try { }
// catch { return; // <-- the end of this block is the end of the return statement.
// Method();
var firstStatement = ((BlockSyntax)node).Statements[0];
if (FormattingRangeHelper.AreTwoTokensOnSameLine(firstTokenOfNode, firstStatement.GetFirstToken()))
{
endToken = firstStatement.GetLastToken();
}
}
else
{
endToken = endToken.GetPreviousToken();
}
}
}
// suppress wrapping on whole construct that owns braces and also brace pair itself if
// it is on same line
AddSuppressWrappingIfOnSingleLineOperation(list, firstTokenOfNode, endToken);
AddSuppressWrappingIfOnSingleLineOperation(list, bracePair.Item1, endToken);
}
示例2: RemoveSuppressOperationForBlock
private void RemoveSuppressOperationForBlock(List<SuppressOperation> list, SyntaxNode node)
{
var bracePair = GetBracePair(node);
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
RemoveSuppressOperation(list, firstTokenOfNode, bracePair.Item2);
RemoveSuppressOperation(list, bracePair.Item1, bracePair.Item2);
}
示例3: AddBraceSuppressOperations
protected void AddBraceSuppressOperations(List<SuppressOperation> list, SyntaxNode node, SyntaxToken lastToken)
{
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);
}
// We may think we have a complete set of braces, but that may not actually be the case
// due incomplete code. i.e. we have something like:
//
// class C
// {
// int Blah {
// get { return blah
// }
//
// In this case the parse will think that the get-accessor is actually on two lines
// (because it will consume the close curly that more accurately belongs to the class.
//
// Now there are different behaviors we want depending on what the user is doing
// and what we are formatting. For example, if the user hits semicolon at the end of
// "blah", then we want to keep the accessor on a single line. In this scenario we
// effectively want to ignore the following close curly as it may not be important to
// this construct in the mind of the user.
//
// However, say the user hits semicolon, then hits enter, then types a close curly.
// In this scenario we woudl actually want the get-accessor to be formatted over multiple
// lines. The difference here is that because the user just hit close-curly here we can
// consider it as being part of the closest construct and we can consider its placement
// when deciding if the construct is on a single line.
var endBrace = bracePair.Item2;
if (lastToken.Kind() != SyntaxKind.CloseBraceToken &&
lastToken.Kind() != SyntaxKind.EndOfFileToken &&
!endBrace.IsMissing)
{
// The user didn't just type the close brace. So any close brace we have may
// actually belong to a containing construct. See if any containers are missing
// a close brace, and if so, act as if our own close brace is missing.
if (SomeParentHasMissingCloseBrace(node.Parent))
{
endBrace = endBrace.GetPreviousToken();
}
}
// suppress wrapping on whole construct that owns braces and also brace pair itself if
// it is on same line
AddSuppressWrappingIfOnSingleLineOperation(list, firstTokenOfNode, endBrace);
AddSuppressWrappingIfOnSingleLineOperation(list, bracePair.Item1, endBrace);
}