本文整理汇总了C#中ExpressionSyntax.SkipParens方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSyntax.SkipParens方法的具体用法?C# ExpressionSyntax.SkipParens怎么用?C# ExpressionSyntax.SkipParens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionSyntax
的用法示例。
在下文中一共展示了ExpressionSyntax.SkipParens方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnpackNullableValueAccess
internal static ExpressionSyntax UnpackNullableValueAccess(SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken)
{
var expr = expression.SkipParens();
if (!expr.IsKind(SyntaxKind.SimpleMemberAccessExpression))
return expression;
var info = semanticModel.GetTypeInfo(((MemberAccessExpressionSyntax)expr).Expression, cancellationToken);
if (!info.ConvertedType.IsNullableType())
return expression;
return ((MemberAccessExpressionSyntax)expr).Expression;
}
开发者ID:yeaicc,项目名称:RefactoringEssentials,代码行数:10,代码来源:ConvertConditionalTernaryToNullCoalescingAnalyzer.cs
示例2: AnalyzeBinaryExpression
static ExpressionSyntax AnalyzeBinaryExpression(ExpressionSyntax node)
{
var bOp = node.SkipParens() as BinaryExpressionSyntax;
if (bOp == null)
return null;
if (bOp.IsKind(SyntaxKind.NotEqualsExpression) || bOp.IsKind(SyntaxKind.EqualsExpression))
{
if (bOp.Left != null && bOp.Left.SkipParens().IsKind(SyntaxKind.NullLiteralExpression))
return bOp.Right;
if (bOp.Right != null && bOp.Right.SkipParens().IsKind(SyntaxKind.NullLiteralExpression))
return bOp.Left;
}
return null;
}
开发者ID:yeaicc,项目名称:RefactoringEssentials,代码行数:14,代码来源:ConvertConditionalTernaryToNullCoalescingAnalyzer.cs
示例3: CheckNullComparison
static bool CheckNullComparison(SyntaxNodeAnalysisContext nodeContext, BinaryExpressionSyntax binaryOperatorExpression, ExpressionSyntax right, ExpressionSyntax nullNode, ref Diagnostic diagnostic)
{
if (!binaryOperatorExpression.IsKind(SyntaxKind.EqualsExpression) && !binaryOperatorExpression.IsKind(SyntaxKind.NotEqualsExpression))
return false;
// note null == null is checked by similiar expression comparison.
var expr = right.SkipParens();
var rr = nodeContext.SemanticModel.GetTypeInfo(expr);
if (rr.Type == null)
return false;
var returnType = rr.Type;
if (returnType != null && returnType.IsValueType && !returnType.IsPointerType())
{
// nullable check
if (returnType.IsNullableType())
return false;
var conversion = nodeContext.SemanticModel.GetConversion(nullNode);
if (conversion.IsUserDefined)
return false;
// check for user operators
foreach (IMethodSymbol op in returnType.GetMembers().OfType<IMethodSymbol>().Where(m => m.MethodKind == MethodKind.UserDefinedOperator && m.Parameters.Length == 2))
{
if (op.Parameters[0].Type.IsReferenceType == false && op.Parameters[1].Type.IsReferenceType == false)
continue;
if (binaryOperatorExpression.IsKind(SyntaxKind.EqualsExpression) && op.Name == "op_Equality")
return false;
if (binaryOperatorExpression.IsKind(SyntaxKind.NotEqualsExpression) && op.Name == "op_Inequality")
return false;
}
diagnostic = Diagnostic.Create(
descriptor,
binaryOperatorExpression.GetLocation(),
!binaryOperatorExpression.IsKind(SyntaxKind.EqualsExpression) ? "true" : "false"
);
return true;
}
return false;
}
示例4: AreConditionsEqual
public static bool AreConditionsEqual(ExpressionSyntax cond1, ExpressionSyntax cond2)
{
if (cond1 == null || cond2 == null)
return false;
return cond1.SkipParens().IsEquivalentTo(cond2.SkipParens(), true);
}
示例5: ExtractLambda
static bool ExtractLambda(ArgumentSyntax argument, out ParameterSyntax parameter, out ExpressionSyntax body)
{
if (argument.Expression is SimpleLambdaExpressionSyntax)
{
var simple = (SimpleLambdaExpressionSyntax)argument.Expression;
parameter = simple.Parameter;
body = simple.Body as ExpressionSyntax;
if (body == null)
return false;
body = body.SkipParens();
return true;
}
parameter = null;
body = null;
return false;
}