本文整理汇总了C#中MemberAccessExpressionSyntax.IsParentKind方法的典型用法代码示例。如果您正苦于以下问题:C# MemberAccessExpressionSyntax.IsParentKind方法的具体用法?C# MemberAccessExpressionSyntax.IsParentKind怎么用?C# MemberAccessExpressionSyntax.IsParentKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemberAccessExpressionSyntax
的用法示例。
在下文中一共展示了MemberAccessExpressionSyntax.IsParentKind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InferTypeForExpressionOfMemberAccessExpression
private IEnumerable<TypeInferenceInfo> InferTypeForExpressionOfMemberAccessExpression(
MemberAccessExpressionSyntax memberAccessExpression)
{
// If we're on the left side of a dot, it's possible in a few cases
// to figure out what type we should be. Specifically, if we have
//
// await foo.ConfigureAwait()
//
// then we can figure out what 'foo' should be based on teh await
// context.
var name = memberAccessExpression.Name.Identifier.Value;
if (name.Equals(nameof(Task<int>.ConfigureAwait)) &&
memberAccessExpression.IsParentKind(SyntaxKind.InvocationExpression) &&
memberAccessExpression.Parent.IsParentKind(SyntaxKind.AwaitExpression))
{
return InferTypes((ExpressionSyntax)memberAccessExpression.Parent);
}
else if (name.Equals(nameof(Task<int>.ContinueWith)))
{
// foo.ContinueWith(...)
// We want to infer Task<T>. For now, we'll just do Task<object>,
// in the future it would be nice to figure out the actual result
// type based on the argument to ContinueWith.
var taskOfT = this.Compilation.TaskOfTType();
if (taskOfT != null)
{
return SpecializedCollections.SingletonEnumerable(
new TypeInferenceInfo(taskOfT.Construct(this.Compilation.ObjectType)));
}
}
else if (name.Equals(nameof(Enumerable.Select)) ||
name.Equals(nameof(Enumerable.Where)))
{
var ienumerableType = this.Compilation.IEnumerableOfTType();
// foo.Select
// We want to infer IEnumerable<T>. We can try to figure out what
// T if we get a delegate as the first argument to Select/Where.
if (ienumerableType != null && memberAccessExpression.IsParentKind(SyntaxKind.InvocationExpression))
{
var invocation = (InvocationExpressionSyntax)memberAccessExpression.Parent;
if (invocation.ArgumentList.Arguments.Count > 0)
{
var argumentExpression = invocation.ArgumentList.Arguments[0].Expression;
if (argumentExpression != null)
{
var argumentTypes = GetTypes(argumentExpression);
var delegateType = argumentTypes.FirstOrDefault().InferredType.GetDelegateType(this.Compilation);
var typeArg = delegateType?.TypeArguments.Length > 0
? delegateType.TypeArguments[0]
: this.Compilation.ObjectType;
if (IsUnusableType(typeArg) && argumentExpression is LambdaExpressionSyntax)
{
typeArg = InferTypeForFirstParameterOfLambda((LambdaExpressionSyntax)argumentExpression) ??
this.Compilation.ObjectType;
}
return SpecializedCollections.SingletonEnumerable(
new TypeInferenceInfo(ienumerableType.Construct(typeArg)));
}
}
}
}
return SpecializedCollections.EmptyEnumerable<TypeInferenceInfo>();
}
示例2: AddMemberAccessExpressionTerms
private static void AddMemberAccessExpressionTerms(MemberAccessExpressionSyntax memberAccessExpression, IList<string> terms, ref ExpressionType expressionType)
{
var flags = ExpressionType.Invalid;
// These operators always have a RHS of a name node, which we know would
// "claim" to be a valid term, but is not valid without the LHS present.
// So, we don't bother collecting anything from the RHS...
AddSubExpressionTerms(memberAccessExpression.Expression, terms, ref flags);
// If the LHS says it's a valid term, then we add it ONLY if our PARENT
// is NOT another dot/arrow. This allows the expression 'a.b.c.d' to
// add both 'a.b.c.d' and 'a.b.c', but not 'a.b' and 'a'.
if (IsValidTerm(flags) &&
!memberAccessExpression.IsParentKind(SyntaxKind.SimpleMemberAccessExpression) &&
!memberAccessExpression.IsParentKind(SyntaxKind.PointerMemberAccessExpression))
{
terms.Add(ConvertToString(memberAccessExpression.Expression));
}
// And this expression itself is a valid term if the LHS is a valid
// expression, and its PARENT is not an invocation.
if (IsValidExpression(flags) &&
!memberAccessExpression.IsParentKind(SyntaxKind.InvocationExpression))
{
expressionType = ExpressionType.ValidTerm;
}
else
{
expressionType = ExpressionType.ValidExpression;
}
}