本文整理匯總了C#中BinaryExpressionSyntax.IsParentKind方法的典型用法代碼示例。如果您正苦於以下問題:C# BinaryExpressionSyntax.IsParentKind方法的具體用法?C# BinaryExpressionSyntax.IsParentKind怎麽用?C# BinaryExpressionSyntax.IsParentKind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BinaryExpressionSyntax
的用法示例。
在下文中一共展示了BinaryExpressionSyntax.IsParentKind方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: PerformAction
static Document PerformAction(Document document, SyntaxNode root, BinaryExpressionSyntax bop)
{
var nodeToReplace = bop.IsParentKind(SyntaxKind.ParenthesizedExpression) ? bop.Parent : bop;
var castExpr = (ExpressionSyntax)SyntaxFactory.CastExpression(bop.Right as TypeSyntax, CSharpUtil.AddParensIfRequired(bop.Left.WithoutLeadingTrivia().WithoutTrailingTrivia())).WithLeadingTrivia(bop.GetLeadingTrivia()).WithTrailingTrivia(bop.GetTrailingTrivia());
var newRoot = root.ReplaceNode((SyntaxNode)nodeToReplace, castExpr);
return document.WithSyntaxRoot(newRoot);
}
開發者ID:alecor191,項目名稱:RefactoringEssentials,代碼行數:8,代碼來源:ReplaceSafeCastWithDirectCastCodeRefactoringProvider.cs
示例2: VisitBinaryExpression
public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
{
_cancellationToken.ThrowIfCancellationRequested();
// Special case: We parenthesize to avoid a situation where inlining an
// expression can cause code to parse differently. The canonical case is...
//
// var x = 0;
// var y = (1 + 2);
// var z = new[] { x < x, x > y };
//
// Inlining 'y' in the code above will produce code that parses differently
// (i.e. as a generic method invocation).
//
// var z = new[] { x < x, x > (1 + 2) };
var result = (BinaryExpressionSyntax)base.VisitBinaryExpression(node);
if ((node.Kind() == SyntaxKind.GreaterThanExpression || node.Kind() == SyntaxKind.RightShiftExpression) && !node.IsParentKind(SyntaxKind.ParenthesizedExpression))
{
return result.Parenthesize();
}
return result;
}