本文整理汇总了C#中ExpressionSyntax.WalkUpParentheses方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSyntax.WalkUpParentheses方法的具体用法?C# ExpressionSyntax.WalkUpParentheses怎么用?C# ExpressionSyntax.WalkUpParentheses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionSyntax
的用法示例。
在下文中一共展示了ExpressionSyntax.WalkUpParentheses方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOuterCastType
private static ITypeSymbol GetOuterCastType(ExpressionSyntax expression, SemanticModel semanticModel, out bool parentIsOrAsExpression)
{
expression = expression.WalkUpParentheses();
parentIsOrAsExpression = false;
var parentNode = expression.Parent;
if (parentNode == null)
{
return null;
}
if (parentNode.IsKind(SyntaxKind.CastExpression))
{
var castExpression = (CastExpressionSyntax)parentNode;
return semanticModel.GetTypeInfo(castExpression).Type;
}
if (parentNode.IsKind(SyntaxKind.IsExpression) ||
parentNode.IsKind(SyntaxKind.AsExpression))
{
parentIsOrAsExpression = true;
return null;
}
if (parentNode.IsKind(SyntaxKind.ArrayRankSpecifier))
{
return semanticModel.Compilation.GetSpecialType(SpecialType.System_Int32);
}
if (parentNode.IsKind(SyntaxKind.SimpleMemberAccessExpression))
{
var memberAccess = (MemberAccessExpressionSyntax)parentNode;
if (memberAccess.Expression == expression)
{
var memberSymbol = semanticModel.GetSymbolInfo(memberAccess).Symbol;
if (memberSymbol != null)
{
return memberSymbol.ContainingType;
}
}
}
if (parentNode.IsKind(SyntaxKind.ConditionalExpression) &&
((ConditionalExpressionSyntax)parentNode).Condition == expression)
{
return semanticModel.Compilation.GetSpecialType(SpecialType.System_Boolean);
}
if ((parentNode is PrefixUnaryExpressionSyntax || parentNode is PostfixUnaryExpressionSyntax) &&
!semanticModel.GetConversion(expression).IsUserDefined)
{
var parentEpression = (ExpressionSyntax)parentNode;
return GetOuterCastType(parentEpression, semanticModel, out parentIsOrAsExpression) ?? semanticModel.GetTypeInfo(parentEpression).ConvertedType;
}
return null;
}
示例2: InferTypesWorker
private IEnumerable<ITypeSymbol> InferTypesWorker(ExpressionSyntax expression)
{
expression = expression.WalkUpParentheses();
var parent = expression.Parent;
return parent.TypeSwitch(
(AnonymousObjectMemberDeclaratorSyntax memberDeclarator) => InferTypeInMemberDeclarator(memberDeclarator),
(ArgumentSyntax argument) => InferTypeInArgument(argument),
(CheckedExpressionSyntax checkedExpression) => InferTypes(checkedExpression),
(ArrayCreationExpressionSyntax arrayCreationExpression) => InferTypeInArrayCreationExpression(arrayCreationExpression),
(ArrayRankSpecifierSyntax arrayRankSpecifier) => InferTypeInArrayRankSpecifier(arrayRankSpecifier),
(ArrayTypeSyntax arrayType) => InferTypeInArrayType(arrayType),
(AttributeArgumentSyntax attribute) => InferTypeInAttributeArgument(attribute),
(AttributeSyntax attribute) => InferTypeInAttribute(attribute),
(BinaryExpressionSyntax binaryExpression) => InferTypeInBinaryExpression(binaryExpression, expression),
(CastExpressionSyntax castExpression) => InferTypeInCastExpression(castExpression, expression),
(CatchDeclarationSyntax catchDeclaration) => InferTypeInCatchDeclaration(catchDeclaration),
(ConditionalExpressionSyntax conditionalExpression) => InferTypeInConditionalExpression(conditionalExpression, expression),
(DoStatementSyntax doStatement) => InferTypeInDoStatement(doStatement),
(EqualsValueClauseSyntax equalsValue) => InferTypeInEqualsValueClause(equalsValue),
(ExpressionStatementSyntax expressionStatement) => InferTypeInExpressionStatement(expressionStatement),
(ForEachStatementSyntax forEachStatement) => InferTypeInForEachStatement(forEachStatement, expression),
(ForStatementSyntax forStatement) => InferTypeInForStatement(forStatement, expression),
(IfStatementSyntax ifStatement) => InferTypeInIfStatement(ifStatement),
(InitializerExpressionSyntax initializerExpression) => InferTypeInInitializerExpression(initializerExpression, expression),
(LockStatementSyntax lockStatement) => InferTypeInLockStatement(lockStatement),
(NameEqualsSyntax nameEquals) => InferTypeInNameEquals(nameEquals),
(ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpression) => InferTypeInParenthesizedLambdaExpression(parenthesizedLambdaExpression),
(PostfixUnaryExpressionSyntax postfixUnary) => InferTypeInPostfixUnaryExpression(postfixUnary),
(PrefixUnaryExpressionSyntax prefixUnary) => InferTypeInPrefixUnaryExpression(prefixUnary),
(ReturnStatementSyntax returnStatement) => InferTypeForReturnStatement(returnStatement),
(SimpleLambdaExpressionSyntax simpleLambdaExpression) => InferTypeInSimpleLambdaExpression(simpleLambdaExpression),
(SwitchLabelSyntax switchLabel) => InferTypeInSwitchLabel(switchLabel),
(SwitchStatementSyntax switchStatement) => InferTypeInSwitchStatement(switchStatement),
(ThrowStatementSyntax throwStatement) => InferTypeInThrowStatement(throwStatement),
(UsingStatementSyntax usingStatement) => InferTypeInUsingStatement(usingStatement),
(WhileStatementSyntax whileStatement) => InferTypeInWhileStatement(whileStatement),
(YieldStatementSyntax yieldStatement) => InferTypeInYieldStatement(yieldStatement),
_ => SpecializedCollections.EmptyEnumerable<ITypeSymbol>());
}
示例3: InferTypesWorker_DoNotCallDirectly
protected override IEnumerable<TypeInferenceInfo> InferTypesWorker_DoNotCallDirectly(
ExpressionSyntax expression)
{
expression = expression.WalkUpParentheses();
var parent = expression.Parent;
return parent.TypeSwitch(
(AnonymousObjectMemberDeclaratorSyntax memberDeclarator) => InferTypeInMemberDeclarator(memberDeclarator),
(ArgumentSyntax argument) => InferTypeInArgument(argument),
(ArrayCreationExpressionSyntax arrayCreationExpression) => InferTypeInArrayCreationExpression(arrayCreationExpression),
(ArrayRankSpecifierSyntax arrayRankSpecifier) => InferTypeInArrayRankSpecifier(arrayRankSpecifier),
(ArrayTypeSyntax arrayType) => InferTypeInArrayType(arrayType),
(ArrowExpressionClauseSyntax arrowClause) => InferTypeInArrowExpressionClause(arrowClause),
(AssignmentExpressionSyntax assignmentExpression) => InferTypeInBinaryOrAssignmentExpression(assignmentExpression, assignmentExpression.OperatorToken, assignmentExpression.Left, assignmentExpression.Right, expression),
(AttributeArgumentSyntax attribute) => InferTypeInAttributeArgument(attribute),
(AttributeSyntax attribute) => InferTypeInAttribute(attribute),
(AwaitExpressionSyntax awaitExpression) => InferTypeInAwaitExpression(awaitExpression),
(BinaryExpressionSyntax binaryExpression) => InferTypeInBinaryOrAssignmentExpression(binaryExpression, binaryExpression.OperatorToken, binaryExpression.Left, binaryExpression.Right, expression),
(CastExpressionSyntax castExpression) => InferTypeInCastExpression(castExpression, expression),
(CatchDeclarationSyntax catchDeclaration) => InferTypeInCatchDeclaration(catchDeclaration),
(CatchFilterClauseSyntax catchFilterClause) => InferTypeInCatchFilterClause(catchFilterClause),
(CheckedExpressionSyntax checkedExpression) => InferTypes(checkedExpression),
(ConditionalAccessExpressionSyntax conditionalAccessExpression) => InferTypeInConditionalAccessExpression(conditionalAccessExpression),
(ConditionalExpressionSyntax conditionalExpression) => InferTypeInConditionalExpression(conditionalExpression, expression),
(DoStatementSyntax doStatement) => InferTypeInDoStatement(doStatement),
(EqualsValueClauseSyntax equalsValue) => InferTypeInEqualsValueClause(equalsValue),
(ExpressionStatementSyntax expressionStatement) => InferTypeInExpressionStatement(expressionStatement),
(ForEachStatementSyntax forEachStatement) => InferTypeInForEachStatement(forEachStatement, expression),
(ForStatementSyntax forStatement) => InferTypeInForStatement(forStatement, expression),
(IfStatementSyntax ifStatement) => InferTypeInIfStatement(ifStatement),
(InitializerExpressionSyntax initializerExpression) => InferTypeInInitializerExpression(initializerExpression, expression),
(IsPatternExpressionSyntax isPatternExpression) => InferTypeInIsPatternExpression(isPatternExpression, expression),
(LockStatementSyntax lockStatement) => InferTypeInLockStatement(lockStatement),
(MemberAccessExpressionSyntax memberAccessExpression) => InferTypeInMemberAccessExpression(memberAccessExpression, expression),
(NameEqualsSyntax nameEquals) => InferTypeInNameEquals(nameEquals),
(ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpression) => InferTypeInParenthesizedLambdaExpression(parenthesizedLambdaExpression),
(PostfixUnaryExpressionSyntax postfixUnary) => InferTypeInPostfixUnaryExpression(postfixUnary),
(PrefixUnaryExpressionSyntax prefixUnary) => InferTypeInPrefixUnaryExpression(prefixUnary),
(ReturnStatementSyntax returnStatement) => InferTypeForReturnStatement(returnStatement),
(SimpleLambdaExpressionSyntax simpleLambdaExpression) => InferTypeInSimpleLambdaExpression(simpleLambdaExpression),
(SwitchLabelSyntax switchLabel) => InferTypeInSwitchLabel(switchLabel),
(SwitchStatementSyntax switchStatement) => InferTypeInSwitchStatement(switchStatement),
(ThrowStatementSyntax throwStatement) => InferTypeInThrowStatement(throwStatement),
(UsingStatementSyntax usingStatement) => InferTypeInUsingStatement(usingStatement),
(WhileStatementSyntax whileStatement) => InferTypeInWhileStatement(whileStatement),
(YieldStatementSyntax yieldStatement) => InferTypeInYieldStatement(yieldStatement),
_ => SpecializedCollections.EmptyEnumerable<TypeInferenceInfo>());
}
示例4: IsInDelegateCreationExpression
private static bool IsInDelegateCreationExpression(ExpressionSyntax expression, SemanticModel semanticModel)
{
var argument = expression.WalkUpParentheses().Parent as ArgumentSyntax;
if (argument == null)
{
return false;
}
var argumentList = argument.Parent as ArgumentListSyntax;
if (argumentList == null)
{
return false;
}
var objectCreation = argumentList.Parent as ObjectCreationExpressionSyntax;
if (objectCreation == null)
{
return false;
}
var typeSymbol = semanticModel.GetSymbolInfo(objectCreation.Type).Symbol;
return typeSymbol != null
&& typeSymbol.IsDelegateType();
}
示例5: UserDefinedConversionIsAllowed
private static bool UserDefinedConversionIsAllowed(ExpressionSyntax expression, SemanticModel semanticModel)
{
expression = expression.WalkUpParentheses();
var parentNode = expression.Parent;
if (parentNode == null)
{
return false;
}
if (parentNode.IsKind(SyntaxKind.ThrowStatement))
{
return false;
}
return true;
}
示例6: InferTypesWorker_DoNotCallDirectly
protected override IEnumerable<TypeInferenceInfo> InferTypesWorker_DoNotCallDirectly(
ExpressionSyntax expression)
{
expression = expression.WalkUpParentheses();
var parent = expression.Parent;
switch (parent)
{
case AnonymousObjectMemberDeclaratorSyntax memberDeclarator: return InferTypeInMemberDeclarator(memberDeclarator);
case ArgumentSyntax argument: return InferTypeInArgument(argument);
case ArrayCreationExpressionSyntax arrayCreationExpression: return InferTypeInArrayCreationExpression(arrayCreationExpression);
case ArrayRankSpecifierSyntax arrayRankSpecifier: return InferTypeInArrayRankSpecifier(arrayRankSpecifier);
case ArrayTypeSyntax arrayType: return InferTypeInArrayType(arrayType);
case ArrowExpressionClauseSyntax arrowClause: return InferTypeInArrowExpressionClause(arrowClause);
case AssignmentExpressionSyntax assignmentExpression: return InferTypeInBinaryOrAssignmentExpression(assignmentExpression, assignmentExpression.OperatorToken, assignmentExpression.Left, assignmentExpression.Right, expression);
case AttributeArgumentSyntax attribute: return InferTypeInAttributeArgument(attribute);
case AttributeSyntax attribute: return InferTypeInAttribute(attribute);
case AwaitExpressionSyntax awaitExpression: return InferTypeInAwaitExpression(awaitExpression);
case BinaryExpressionSyntax binaryExpression: return InferTypeInBinaryOrAssignmentExpression(binaryExpression, binaryExpression.OperatorToken, binaryExpression.Left, binaryExpression.Right, expression);
case CastExpressionSyntax castExpression: return InferTypeInCastExpression(castExpression, expression);
case CatchDeclarationSyntax catchDeclaration: return InferTypeInCatchDeclaration(catchDeclaration);
case CatchFilterClauseSyntax catchFilterClause: return InferTypeInCatchFilterClause(catchFilterClause);
case CheckedExpressionSyntax checkedExpression: return InferTypes(checkedExpression);
case ConditionalAccessExpressionSyntax conditionalAccessExpression: return InferTypeInConditionalAccessExpression(conditionalAccessExpression);
case ConditionalExpressionSyntax conditionalExpression: return InferTypeInConditionalExpression(conditionalExpression, expression);
case DoStatementSyntax doStatement: return InferTypeInDoStatement(doStatement);
case EqualsValueClauseSyntax equalsValue: return InferTypeInEqualsValueClause(equalsValue);
case ExpressionStatementSyntax expressionStatement: return InferTypeInExpressionStatement(expressionStatement);
case ForEachStatementSyntax forEachStatement: return InferTypeInForEachStatement(forEachStatement, expression);
case ForStatementSyntax forStatement: return InferTypeInForStatement(forStatement, expression);
case IfStatementSyntax ifStatement: return InferTypeInIfStatement(ifStatement);
case InitializerExpressionSyntax initializerExpression: return InferTypeInInitializerExpression(initializerExpression, expression);
case IsPatternExpressionSyntax isPatternExpression: return InferTypeInIsPatternExpression(isPatternExpression, expression);
case LockStatementSyntax lockStatement: return InferTypeInLockStatement(lockStatement);
case MemberAccessExpressionSyntax memberAccessExpression: return InferTypeInMemberAccessExpression(memberAccessExpression, expression);
case NameEqualsSyntax nameEquals: return InferTypeInNameEquals(nameEquals);
case ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpression: return InferTypeInParenthesizedLambdaExpression(parenthesizedLambdaExpression);
case PostfixUnaryExpressionSyntax postfixUnary: return InferTypeInPostfixUnaryExpression(postfixUnary);
case PrefixUnaryExpressionSyntax prefixUnary: return InferTypeInPrefixUnaryExpression(prefixUnary);
case ReturnStatementSyntax returnStatement: return InferTypeForReturnStatement(returnStatement);
case SimpleLambdaExpressionSyntax simpleLambdaExpression: return InferTypeInSimpleLambdaExpression(simpleLambdaExpression);
case SwitchLabelSyntax switchLabel: return InferTypeInSwitchLabel(switchLabel);
case SwitchStatementSyntax switchStatement: return InferTypeInSwitchStatement(switchStatement);
case ThrowStatementSyntax throwStatement: return InferTypeInThrowStatement(throwStatement);
case UsingStatementSyntax usingStatement: return InferTypeInUsingStatement(usingStatement);
case WhileStatementSyntax whileStatement: return InferTypeInWhileStatement(whileStatement);
case YieldStatementSyntax yieldStatement: return InferTypeInYieldStatement(yieldStatement);
default: return SpecializedCollections.EmptyEnumerable<TypeInferenceInfo>();
}
}