Exemplo n.º 1
0
            protected override Expression VisitMemberAccess(MemberExpression node)
            {
                if (node.CheckNotNull(nameof(node)).Expression?.NodeType == ExpressionType.Constant)
                {
                    var member = node.Member;
                    if (member.MemberType == MemberTypes.Property &&
                        member.DeclaringType?.IsGenericType == true &&
                        member.DeclaringType?.Type.GetGenericTypeDefinition() == typeof(VariableQueryArgument <>))
                    {
                        var instanceExpression = (ConstantExpression)(Visit(node.Expression) ?? throw new InvalidOperationException("Visit must not return null for non null value."));

                        PropertyInfo propertyInfo;
                        if (instanceExpression.Value is VariableQueryArgument)
                        {
                            propertyInfo = QueryArgumentValuePropertyInfo;
                        }
                        else if (instanceExpression.Value is VariableQueryArgumentList)
                        {
                            propertyInfo = QueryArgumentValueListPropertyInfo;
                        }
                        else
                        {
                            throw new RemoteLinqException($"Expected instance expression of type {nameof(VariableQueryArgument)} {nameof(VariableQueryArgumentList)} but got '{instanceExpression.Value?.GetType().FullName ?? "null"}'");
                        }

                        return(new MemberExpression(instanceExpression, propertyInfo));
                    }
                }

                return(base.VisitMemberAccess(node));
            }
Exemplo n.º 2
0
            protected override Expression VisitMemberAccess(MemberExpression node)
            {
                var member = node.CheckNotNull(nameof(node)).Member;

                if (member.MemberType == MemberTypes.Property &&
                    (string.Equals(member.DeclaringType?.FullName, typeof(VariableQueryArgument).FullName, StringComparison.Ordinal) ||
                     string.Equals(member.DeclaringType?.FullName, typeof(VariableQueryArgumentList).FullName, StringComparison.Ordinal)) &&
                    Visit(node.Expression) is ConstantExpression instanceExpression)
                {
                    var instanceType = instanceExpression.Type;
                    if (instanceType.IsGenericType && instanceType.Type.GetGenericTypeDefinition() == typeof(VariableQueryArgument <>))
                    {
                        var valueType         = instanceType.GenericArguments.Single();
                        var valuePropertyInfo = new PropertyInfo(nameof(VariableQueryArgument.Value), valueType, instanceType);

                        return(new MemberExpression(instanceExpression, valuePropertyInfo));
                    }
                }

                return(base.VisitMemberAccess(node));
            }