protected override ConstantExpression VisitConstant(ConstantExpression expression) { if (IsGenericVariableQueryArgument(expression)) { var valueProperty = expression.Value.GetType().GetProperty("Value"); var value = valueProperty.GetValue(expression.Value); object queryArgument; var collection = value as System.Collections.IEnumerable; if (ReferenceEquals(null, collection) || value is string) { queryArgument = new VariableQueryArgument(value, valueProperty.PropertyType); } else { var elementType = TypeHelper.GetElementType(valueProperty.PropertyType); queryArgument = new VariableQueryArgumentList(collection, elementType); } return(new ConstantExpression(queryArgument)); } return(base.VisitConstant(expression)); }
protected override ConstantExpression VisitConstant(ConstantExpression node) { if (IsGenericVariableQueryArgument(node.CheckNotNull(nameof(node)), out var valueType)) { var valueProperty = node.Value?.GetType().GetProperty(nameof(VariableQueryArgument <object> .Value)); var value = valueProperty?.GetValue(node.Value); object queryArgument; if (value.IsCollection(out var collection)) { var elementType = valueType.GetElementTypeOrThrow(); queryArgument = new VariableQueryArgumentList(collection, elementType); } else { queryArgument = new VariableQueryArgument(value, valueProperty?.PropertyType ?? valueType); } return(new ConstantExpression(queryArgument)); } return(base.VisitConstant(node)); }