Exemplo n.º 1
0
        /// <summary>
        /// Check if <paramref name="invocation"/> is a call to Type.GetMethod.
        /// </summary>
        internal static bool TryMatchGetConstructor(InvocationExpressionSyntax invocation, SyntaxNodeAnalysisContext context, out ReflectedMember member, out Flags flags, out Types types)
        {
            if (invocation.ArgumentList != null &&
                invocation.TryGetTarget(KnownSymbol.Type.GetConstructor, context.SemanticModel, context.CancellationToken, out var getX))
            {
                if (ReflectedMember.TryGetType(invocation, context, out var type, out var typeSource) &&
                    IsKnownSignature(invocation, getX) &&
                    Flags.TryCreate(invocation, getX, context, out flags) &&
                    Types.TryCreate(invocation, getX, context, out types))
                {
                    return(ReflectedMember.TryCreate(getX, invocation, type, typeSource, Name.Ctor, flags.Effective, types, context, out member));
                }

                if (Flags.TryCreate(invocation, getX, context, out flags) &&
                    flags.AreInSufficient)
                {
                    member = new ReflectedMember(type, typeSource, null, getX, invocation, FilterMatch.InSufficientFlags);
                    _      = Types.TryCreate(invocation, getX, context, out types);
                    return(true);
                }
            }

            member = default(ReflectedMember);
            flags  = default(Flags);
            types  = default(Types);
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles GetField, GetEvent, GetMember, GetMethod...
        /// </summary>
        private static bool TryMatchGetX(InvocationExpressionSyntax invocation, QualifiedMethod getXMethod, SyntaxNodeAnalysisContext context, out ReflectedMember member, out Name name, out Flags flags)
        {
            if (invocation.ArgumentList != null &&
                invocation.TryGetTarget(getXMethod, context.SemanticModel, context.CancellationToken, out var getX))
            {
                if (ReflectedMember.TryGetType(invocation, context, out var type, out var typeSource) &&
                    Name.TryCreate(invocation, getX, context, out name) &&
                    Flags.TryCreate(invocation, getX, context, out flags) &&
                    ReflectedMember.TryCreate(getX, invocation, type, typeSource, name, flags.Effective, Types.Any, context, out member))
                {
                    return(true);
                }

                if (getXMethod.Name != "GetNestedType" &&
                    Flags.TryCreate(invocation, getX, context, out flags) &&
                    flags.AreInSufficient)
                {
                    _      = Name.TryCreate(invocation, getX, context, out name);
                    member = new ReflectedMember(type, typeSource, null, getX, invocation, FilterMatch.InSufficientFlags);
                    return(true);
                }
            }

            member = default(ReflectedMember);
            name   = default(Name);
            flags  = default(Flags);
            return(false);
        }