public ExpressionValidationResultWithErrors ValidateField(IFieldExpression fieldExpression, AnalysisContext currentContext)
                {
                    //Check for access to static fields or fields of other objects
                    if (fieldExpression.Instance == null && fieldExpression.Field.DeclaringType == typeof(Depends))
                    {
                        return(ExpressionValidationResultWithErrors.AcceptImidietReturn);
                    }

                    return(ExpressionValidationResultWithErrors.Abstain);
                }
Beispiel #2
0
        private FieldExpression PrepareFieldExpression(IFieldExpression collectionField, IBsonSerializer serializer, PipelineBindingContext bindingContext)
        {
            // Determine whether we generate a query based on a document itself (when a `Document` type is `DocumentExpression`)
            // or the result of previous steps (the `Document` type is `FieldExpression`).
            var parentFieldExpression = collectionField.Document as FieldExpression;

            return(parentFieldExpression == null
                ? new FieldExpression(collectionField.FieldName, serializer)
                : new FieldExpression(new FieldExpression(parentFieldExpression.FieldName, parentFieldExpression.Serializer), collectionField.FieldName, serializer));
        }
        private string GetFieldName(IFieldExpression fieldExpression)
        {
            if (_fieldNameOverride != null)
            {
                return(_fieldNameOverride);
            }

            string fieldNameInString = GetMappedValue(FieldNameMapping, fieldExpression.FieldName);

            if (fieldExpression.ComponentIndex == null)
            {
                return(fieldNameInString);
            }

            return($"{fieldNameInString}_{fieldExpression.ComponentIndex.Value}");
        }
            private bool TryGetPropertyInvocationChain(IExpression expression, out string invocationPath)
            {
                invocationPath = null;
                Stack <string> invocationStack   = new Stack <string>();
                IExpression    currentExpression = expression;

                while ((currentExpression is IMethodCallExpression && currentExpression.SyntaxElementKind != SyntaxElementKind.This) ||
                       currentExpression.SyntaxElementKind == SyntaxElementKind.Box)
                {
                    if (currentExpression.SyntaxElementKind == SyntaxElementKind.Box)
                    {
                        currentExpression = (currentExpression as IUnaryExpression).Value;
                    }
                    else
                    {
                        IMethodCallExpression methodCallExpression = (IMethodCallExpression)currentExpression;

                        if (!(methodCallExpression.Method.IsSpecialName && methodCallExpression.Method.Name.StartsWith("get_")))
                        {
                            return(false);
                        }

                        invocationStack.Push(((IMethodCallExpression)currentExpression).Method.Name.Substring(4));

                        currentExpression = methodCallExpression.Instance;
                    }
                }

                if (currentExpression == null ||
                    (currentExpression.SyntaxElementKind != SyntaxElementKind.This && currentExpression.SyntaxElementKind != SyntaxElementKind.Field))
                {
                    return(false);
                }

                IFieldExpression fieldExpression = currentExpression as IFieldExpression;

                if (fieldExpression != null)
                {
                    invocationStack.Push(fieldExpression.Field.Name);
                }

                invocationPath = invocationStack.Aggregate(new StringBuilder(), (builder, s) => builder.Append('.').Append(s)).Remove(0, 1).ToString();

                return(true);
            }
Beispiel #5
0
        private static string GetFieldName(IFieldExpression fieldExpression, Context state)
        {
            string overrideValue = state.FieldNameOverride?.Invoke(fieldExpression.FieldName, fieldExpression.ComponentIndex);

            if (overrideValue != null)
            {
                return(overrideValue);
            }

            string fieldNameInString = GetMappedValue(FieldNameMapping, fieldExpression.FieldName);

            if (fieldExpression.ComponentIndex == null)
            {
                return(fieldNameInString);
            }

            return($"{fieldNameInString}_{fieldExpression.ComponentIndex.Value}");
        }
            public override object VisitFieldExpression(IFieldExpression expression)
            {
                if (this.context.Current.PropertyAnalysisTerminated)
                {
                    return(expression);
                }

                ExpressionValidationResult validationResult = this.context.Current.Validate(expression);

                if (validationResult.HasFlag(ExpressionValidationResult.ImmediateReturn))
                {
                    return(base.VisitFieldExpression(expression));
                }

                this.methodFieldDependencies.GetOrCreate(this.context.Current.CurrentMethod, () => new List <FieldInfo>()).AddIfNew(expression.Field);

                return(base.VisitFieldExpression(expression));
            }
                public ExpressionValidationResult Validate(IExpression expression, AnalysisContext currentContext)
                {
                    IMethodCallExpression methodCallExpression = expression as IMethodCallExpression;

                    if (methodCallExpression != null)
                    {
                        return(this.ProcessResults(
                                   this.methodCallValidators.Select(v => v.ValidateMethod(methodCallExpression, currentContext)), currentContext));
                    }

                    IFieldExpression fieldExpression = expression as IFieldExpression;

                    if (fieldExpression != null)
                    {
                        return(this.ProcessResults(this.fieldValidators.Select(v => v.ValidateField(fieldExpression, currentContext)), currentContext));
                    }

                    return(ExpressionValidationResult.Abstain);
                }
                public ExpressionValidationResultWithErrors ValidateField(IFieldExpression fieldExpression, AnalysisContext currentContext)
                {
                    //Check for access to static fields or fields of other objects
                    if (fieldExpression.Instance == null || fieldExpression.Instance.SyntaxElementKind != SyntaxElementKind.This)
                    {
                        // Method contains direct access to a field of another class.
                        if (!currentContext.IsNotifyPropertyChangedSafeProperty)
                        {
                            return(new ExpressionValidationResultWithErrors(ExpressionValidationResult.RejectImmediateReturn)
                            {
                                MessageId = "DOM001",
                                SeverityType = SeverityType.Error,
                                MessageArguments = new object[] { currentContext.CurrentProperty, currentContext.CurrentMethod }
                            });
                        }

                        return(ExpressionValidationResultWithErrors.AcceptImidietReturn);
                    }

                    return(ExpressionValidationResultWithErrors.Abstain);
                }
Beispiel #9
0
 protected static IndentedStringBuilder AppendColumnName(SearchParameterQueryGeneratorContext context, Column column, IFieldExpression expression)
 {
     return(AppendColumnName(context, column, expression.ComponentIndex));
 }
Beispiel #10
0
        private static Expression GetRule(TypeCreator typeCreator, Dictionary <string, JToken> props, Type returnType, IFieldExpression fieldExpression)
        {
            var rule = (IWorQLessRuleBooster)Reflection.CreateRule(returnType, props["name"].ToObject <string>(), new Type[] { returnType }, null);

            rule.FieldExpression = fieldExpression;
            rule.Value           = props["value"].ToObject <object>();

            return((Expression)rule
                   .GetType()
                   .GetProperty(nameof(IProjection <object, object> .Predicate))
                   .GetValue(rule));
        }
Beispiel #11
0
        private static Expression GetRule(TypeCreator typeCreator, JObject jObject, Type returnType, IFieldExpression fieldExpression)
        {
            var props = jObject.Properties()
                        .ToDictionary(o => o.Name, o => o.Value);

            return(GetRule(typeCreator, props, returnType, fieldExpression));
        }
                public ExpressionValidationResultWithErrors ValidateField( IFieldExpression fieldExpression, AnalysisContext currentContext )
                {
                    //Check for access to static fields or fields of other objects
                    if ( fieldExpression.Instance == null || fieldExpression.Instance.SyntaxElementKind != SyntaxElementKind.This )
                    {
                        // Method contains direct access to a field of another class.
                        if ( !currentContext.IsNotifyPropertyChangedSafeProperty )
                        {
                            return new ExpressionValidationResultWithErrors( ExpressionValidationResult.RejectImmediateReturn )
                                {
                                    MessageId = "DOM001",
                                    SeverityType = SeverityType.Error,
                                    MessageArguments = new object[] { currentContext.CurrentProperty, currentContext.CurrentMethod }
                                };
                        }

                        return ExpressionValidationResultWithErrors.AcceptImidietReturn;
                    }

                    return ExpressionValidationResultWithErrors.Abstain;
                }
                public ExpressionValidationResultWithErrors ValidateField( IFieldExpression fieldExpression, AnalysisContext currentContext )
                {
                    //Check for access to static fields or fields of other objects
                    if ( fieldExpression.Instance == null && fieldExpression.Field.DeclaringType == typeof(Depends) )
                    {
                        return ExpressionValidationResultWithErrors.AcceptImidietReturn;
                    }

                    return ExpressionValidationResultWithErrors.Abstain;
                }
            public override object VisitFieldExpression( IFieldExpression expression )
            {
                if ( this.context.Current.PropertyAnalysisTerminated )
                {
                    return expression;
                }

                ExpressionValidationResult validationResult = this.context.Current.Validate( expression );

                if ( validationResult.HasFlag( ExpressionValidationResult.ImmediateReturn ) )
                {
                    return base.VisitFieldExpression( expression );
                }

                this.methodFieldDependencies.GetOrCreate( this.context.Current.CurrentMethod, () => new List<FieldInfo>() ).AddIfNew( expression.Field );

                return base.VisitFieldExpression( expression );
            }