本文整理汇总了C#中SyntaxToken.IsPossibleTupleElementNameContext方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.IsPossibleTupleElementNameContext方法的具体用法?C# SyntaxToken.IsPossibleTupleElementNameContext怎么用?C# SyntaxToken.IsPossibleTupleElementNameContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxToken
的用法示例。
在下文中一共展示了SyntaxToken.IsPossibleTupleElementNameContext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsLambdaExpression
private bool IsLambdaExpression(SemanticModel semanticModel, int position, SyntaxToken token, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
{
// Typing a generic type parameter, the tree might look like a binary expression around the < token.
// If we infer a delegate type here (because that's what on the other side of the binop),
// ignore it.
if (token.Kind() == SyntaxKind.LessThanToken && token.Parent is BinaryExpressionSyntax)
{
return false;
}
// We might be in the arguments to a parenthesized lambda
if (token.Kind() == SyntaxKind.OpenParenToken || token.Kind() == SyntaxKind.CommaToken)
{
if (token.Parent != null && token.Parent is ParameterListSyntax)
{
return token.Parent.Parent != null && token.Parent.Parent is ParenthesizedLambdaExpressionSyntax;
}
}
// A lambda that is being typed may be parsed as a tuple without names
// For example, "(a, b" could be the start of either a tuple or lambda
// But "(a: b, c" cannot be a lambda
if (token.IsPossibleTupleElementNameContext(position) && token.Parent.IsKind(SyntaxKind.TupleExpression) &&
!((TupleExpressionSyntax)token.Parent).HasNames())
{
position = token.Parent.SpanStart;
}
// Walk up a single level to allow for typing the beginning of a lambda:
// new AssemblyLoadEventHandler(($$
if (token.Kind() == SyntaxKind.OpenParenToken &&
token.Parent.Kind() == SyntaxKind.ParenthesizedExpression)
{
position = token.Parent.SpanStart;
}
// WorkItem 834609: Automatic brace completion inserts the closing paren, making it
// like a cast.
if (token.Kind() == SyntaxKind.OpenParenToken &&
token.Parent.Kind() == SyntaxKind.CastExpression)
{
position = token.Parent.SpanStart;
}
// If we're an argument to a function with multiple overloads,
// open the builder if any overload takes a delegate at our argument position
var inferredTypeInfo = typeInferrer.GetTypeInferenceInfo(semanticModel, position, cancellationToken: cancellationToken);
return inferredTypeInfo.Any(type => GetDelegateType(type, semanticModel.Compilation).IsDelegateType());
}