コード例 #1
0
        private static bool TryGetX(SyntaxNodeAnalysisContext context, out ReflectedMember member, out Name name, out Flags flags, out Types types)
        {
            name = default(Name);
            if (context.Node is InvocationExpressionSyntax candidate)
            {
                return(GetX.TryMatchGetConstructor(candidate, context, out member, out flags, out types) ||
                       GetX.TryMatchGetEvent(candidate, context, out member, out name, out flags) ||
                       GetX.TryMatchGetField(candidate, context, out member, out name, out flags) ||
                       GetX.TryMatchGetMethod(candidate, context, out member, out name, out flags, out types) ||
                       GetX.TryMatchGetNestedType(candidate, context, out member, out name, out flags) ||
                       GetX.TryMatchGetProperty(candidate, context, out member, out name, out flags, out types));
            }

            member = default(ReflectedMember);
            flags  = default(Flags);
            types  = default(Types);
            return(false);
        }
コード例 #2
0
        internal static bool TryGet(ExpressionSyntax expression, SyntaxNodeAnalysisContext context, out EventInfo eventInfo)
        {
            switch (expression)
            {
            case InvocationExpressionSyntax invocation when GetX.TryMatchGetEvent(invocation, context, out var member, out _, out _) &&
                member.Symbol is IEventSymbol @event:
                eventInfo = new EventInfo(member.ReflectedType, @event);

                return(true);
            }

            if (expression.IsEither(SyntaxKind.IdentifierName, SyntaxKind.SimpleMemberAccessExpression) &&
                context.SemanticModel.TryGetSymbol(expression, context.CancellationToken, out ISymbol local))
            {
                eventInfo = default(EventInfo);
                return(AssignedValue.TryGetSingle(local, context.SemanticModel, context.CancellationToken, out var assignedValue) &&
                       TryGet(assignedValue, context, out eventInfo));
            }

            eventInfo = default(EventInfo);
            return(false);
        }