internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
 {
     CodePropertyReferenceExpression expression2 = (CodePropertyReferenceExpression) expression;
     CodeExpression targetObject = expression2.TargetObject;
     if (analysis.Validation.ExpressionInfo(targetObject) == null)
     {
         InvalidOperationException exception = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
         exception.Data["ErrorObject"] = targetObject;
         throw exception;
     }
     RulePropertyExpressionInfo info2 = analysis.Validation.ExpressionInfo(expression2) as RulePropertyExpressionInfo;
     if (info2 == null)
     {
         InvalidOperationException exception2 = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
         exception2.Data["ErrorObject"] = expression2;
         throw exception2;
     }
     PropertyInfo propertyInfo = info2.PropertyInfo;
     List<CodeExpression> attributedExprs = new List<CodeExpression>();
     analysis.AnalyzeRuleAttributes(propertyInfo, targetObject, qualifier, null, null, attributedExprs);
     if (!attributedExprs.Contains(targetObject))
     {
         RuleExpressionWalker.AnalyzeUsage(analysis, targetObject, isRead, isWritten, new RulePathQualifier(propertyInfo.Name, qualifier));
     }
 }
Exemple #2
0
        internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
        {
            CodePropertyReferenceExpression expression2 = (CodePropertyReferenceExpression)expression;
            CodeExpression targetObject = expression2.TargetObject;

            if (analysis.Validation.ExpressionInfo(targetObject) == null)
            {
                InvalidOperationException exception = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
                exception.Data["ErrorObject"] = targetObject;
                throw exception;
            }
            RulePropertyExpressionInfo info2 = analysis.Validation.ExpressionInfo(expression2) as RulePropertyExpressionInfo;

            if (info2 == null)
            {
                InvalidOperationException exception2 = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
                exception2.Data["ErrorObject"] = expression2;
                throw exception2;
            }
            PropertyInfo          propertyInfo    = info2.PropertyInfo;
            List <CodeExpression> attributedExprs = new List <CodeExpression>();

            analysis.AnalyzeRuleAttributes(propertyInfo, targetObject, qualifier, null, null, attributedExprs);
            if (!attributedExprs.Contains(targetObject))
            {
                RuleExpressionWalker.AnalyzeUsage(analysis, targetObject, isRead, isWritten, new RulePathQualifier(propertyInfo.Name, qualifier));
            }
        }
 internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
 {
     CodeIndexerExpression expression2 = (CodeIndexerExpression) expression;
     CodeExpression targetObject = expression2.TargetObject;
     if (analysis.Validation.ExpressionInfo(targetObject) == null)
     {
         InvalidOperationException exception = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
         exception.Data["ErrorObject"] = targetObject;
         throw exception;
     }
     RulePropertyExpressionInfo info2 = analysis.Validation.ExpressionInfo(expression2) as RulePropertyExpressionInfo;
     if (info2 == null)
     {
         InvalidOperationException exception2 = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
         exception2.Data["ErrorObject"] = expression2;
         throw exception2;
     }
     PropertyInfo propertyInfo = info2.PropertyInfo;
     List<CodeExpression> attributedExprs = new List<CodeExpression>();
     analysis.AnalyzeRuleAttributes(propertyInfo, targetObject, qualifier, expression2.Indices, propertyInfo.GetIndexParameters(), attributedExprs);
     if (!attributedExprs.Contains(targetObject))
     {
         RuleExpressionWalker.AnalyzeUsage(analysis, targetObject, isRead, isWritten, qualifier);
     }
     for (int i = 0; i < expression2.Indices.Count; i++)
     {
         CodeExpression item = expression2.Indices[i];
         if (!attributedExprs.Contains(item))
         {
             RuleExpressionWalker.AnalyzeUsage(analysis, item, true, false, null);
         }
     }
 }
 internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
 {
     CodeBinaryOperatorExpression expression2 = (CodeBinaryOperatorExpression) expression;
     RuleBinaryExpressionInfo info = analysis.Validation.ExpressionInfo(expression2) as RuleBinaryExpressionInfo;
     if (info != null)
     {
         MethodInfo methodInfo = info.MethodInfo;
         if (methodInfo != null)
         {
             List<CodeExpression> attributedExprs = new List<CodeExpression>();
             CodeExpressionCollection argExprs = new CodeExpressionCollection();
             argExprs.Add(expression2.Left);
             argExprs.Add(expression2.Right);
             CodeExpression targetExpr = new CodeTypeReferenceExpression(methodInfo.DeclaringType);
             analysis.AnalyzeRuleAttributes(methodInfo, targetExpr, qualifier, argExprs, methodInfo.GetParameters(), attributedExprs);
         }
     }
     RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Left, true, false, null);
     RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Right, true, false, null);
 }
        internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
        {
            CodeBinaryOperatorExpression expression2 = (CodeBinaryOperatorExpression)expression;
            RuleBinaryExpressionInfo     info        = analysis.Validation.ExpressionInfo(expression2) as RuleBinaryExpressionInfo;

            if (info != null)
            {
                MethodInfo methodInfo = info.MethodInfo;
                if (methodInfo != null)
                {
                    List <CodeExpression>    attributedExprs = new List <CodeExpression>();
                    CodeExpressionCollection argExprs        = new CodeExpressionCollection();
                    argExprs.Add(expression2.Left);
                    argExprs.Add(expression2.Right);
                    CodeExpression targetExpr = new CodeTypeReferenceExpression(methodInfo.DeclaringType);
                    analysis.AnalyzeRuleAttributes(methodInfo, targetExpr, qualifier, argExprs, methodInfo.GetParameters(), attributedExprs);
                }
            }
            RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Left, true, false, null);
            RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Right, true, false, null);
        }
Exemple #6
0
        internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
        {
            CodeMethodInvokeExpression expression2  = (CodeMethodInvokeExpression)expression;
            CodeExpression             targetObject = expression2.Method.TargetObject;

            if (analysis.Validation.ExpressionInfo(targetObject) == null)
            {
                InvalidOperationException exception = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
                exception.Data["ErrorObject"] = targetObject;
                throw exception;
            }
            RuleMethodInvokeExpressionInfo info2 = analysis.Validation.ExpressionInfo(expression2) as RuleMethodInvokeExpressionInfo;

            if (info2 == null)
            {
                InvalidOperationException exception2 = new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, new object[0]));
                exception2.Data["ErrorObject"] = expression2;
                throw exception2;
            }
            MethodInfo            methodInfo      = info2.MethodInfo;
            List <CodeExpression> attributedExprs = new List <CodeExpression>();

            analysis.AnalyzeRuleAttributes(methodInfo, targetObject, qualifier, expression2.Parameters, methodInfo.GetParameters(), attributedExprs);
            if (!attributedExprs.Contains(targetObject))
            {
                RuleExpressionWalker.AnalyzeUsage(analysis, targetObject, true, false, null);
            }
            for (int i = 0; i < expression2.Parameters.Count; i++)
            {
                CodeExpression item = expression2.Parameters[i];
                if (!attributedExprs.Contains(item))
                {
                    RuleExpressionWalker.AnalyzeUsage(analysis, item, true, false, null);
                }
            }
        }
        internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
        {
            CodeBinaryOperatorExpression binaryExpr = (CodeBinaryOperatorExpression)expression;

            // Get the method info from the validation so we can look for [RuleRead] and [RuleWrite] attributes.
            RuleBinaryExpressionInfo expressionInfo = analysis.Validation.ExpressionInfo(binaryExpr) as RuleBinaryExpressionInfo;
            if (expressionInfo != null)
            {
                // we may be calling a method, not a default operator
                MethodInfo method = expressionInfo.MethodInfo;
                if (method != null)
                {
                    List<CodeExpression> attributedExprs = new List<CodeExpression>();
                    CodeExpressionCollection arguments = new CodeExpressionCollection();
                    arguments.Add(binaryExpr.Left);
                    arguments.Add(binaryExpr.Right);
                    CodeExpression targetObject = new CodeTypeReferenceExpression(method.DeclaringType);
                    analysis.AnalyzeRuleAttributes(method, targetObject, qualifier, arguments, method.GetParameters(), attributedExprs);
                }
            }

            // Analyze the left & right children.
            RuleExpressionWalker.AnalyzeUsage(analysis, binaryExpr.Left, true, false, null);
            RuleExpressionWalker.AnalyzeUsage(analysis, binaryExpr.Right, true, false, null);
        }
        internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
        {
            string message;

            CodeIndexerExpression indexerExpr = (CodeIndexerExpression)expression;

            // Evaluate the target object and get its type.
            CodeExpression targetObject = indexerExpr.TargetObject;
            RuleExpressionInfo targetExprInfo = analysis.Validation.ExpressionInfo(targetObject);
            if (targetExprInfo == null)  // Oops, someone forgot to validate.
            {
                message = string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated);
                InvalidOperationException exception = new InvalidOperationException(message);
                exception.Data[RuleUserDataKeys.ErrorObject] = targetObject;
                throw exception;
            }

            // Get the property info from the validator so we can look for [RuleRead] and [RuleWrite] attributes.
            RulePropertyExpressionInfo propExprInfo = analysis.Validation.ExpressionInfo(indexerExpr) as RulePropertyExpressionInfo;
            if (propExprInfo == null)  // Oops, someone forgot to validate.
            {
                message = string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated);
                InvalidOperationException exception = new InvalidOperationException(message);
                exception.Data[RuleUserDataKeys.ErrorObject] = indexerExpr;
                throw exception;
            }

            PropertyInfo pi = propExprInfo.PropertyInfo;

            // Look for RuleAttribute's on the invoked indexer property.
            List<CodeExpression> attributedExprs = new List<CodeExpression>();
            analysis.AnalyzeRuleAttributes(pi, targetObject, qualifier, indexerExpr.Indices, pi.GetIndexParameters(), attributedExprs);

            // See if the target object needs default analysis.
            if (!attributedExprs.Contains(targetObject))
            {
                // The property had no [RuleRead] or [RuleWrite] attributes.  The target object is read or
                // written (as the case may be).

                RuleExpressionWalker.AnalyzeUsage(analysis, targetObject, isRead, isWritten, qualifier);
            }

            // See if any of the arguments need default analysis.
            for (int i = 0; i < indexerExpr.Indices.Count; ++i)
            {
                CodeExpression argExpr = indexerExpr.Indices[i];

                if (!attributedExprs.Contains(argExpr))
                {
                    // Similar to the target object, we assume that this method can reads the value
                    // of the parameter, but none of its members.
                    RuleExpressionWalker.AnalyzeUsage(analysis, argExpr, true, false, null);
                }
            }
        }
        internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
        {
            string message;

            CodeMethodInvokeExpression invokeExpr = (CodeMethodInvokeExpression)expression;

            // Get the target object's type.
            CodeExpression targetObject = invokeExpr.Method.TargetObject;
            RuleExpressionInfo targetExprInfo = analysis.Validation.ExpressionInfo(targetObject);
            if (targetExprInfo == null)  // Oops, someone forgot to validate.
            {
                message = string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated);
                InvalidOperationException exception = new InvalidOperationException(message);
                exception.Data[RuleUserDataKeys.ErrorObject] = targetObject;
                throw exception;
            }

            // Get the method info from the validation so we can look for [RuleRead] and [RuleWrite] attributes.
            RuleMethodInvokeExpressionInfo methodExprInfo = analysis.Validation.ExpressionInfo(invokeExpr) as RuleMethodInvokeExpressionInfo;
            if (methodExprInfo == null)  // Oops, someone forgot to validate.
            {
                message = string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated);
                InvalidOperationException exception = new InvalidOperationException(message);
                exception.Data[RuleUserDataKeys.ErrorObject] = invokeExpr;
                throw exception;
            }

            MethodInfo mi = methodExprInfo.MethodInfo;

            // Look for RuleAttribute's on the invoked method.
            List<CodeExpression> attributedExprs = new List<CodeExpression>();
            analysis.AnalyzeRuleAttributes(mi, targetObject, qualifier, invokeExpr.Parameters, mi.GetParameters(), attributedExprs);

            // See if the target object needs default analysis.
            if (!attributedExprs.Contains(targetObject))
            {
                // No applicable [RuleRead] or [RuleWrite] attributes were found on the target object.

                // If we're analyzing for dependencies, assume that this method uses the
                // value of the target object, but nothing beneath it.

                RuleExpressionWalker.AnalyzeUsage(analysis, targetObject, true, false, null);
            }

            // See if any of the arguments need default analysis.
            for (int i = 0; i < invokeExpr.Parameters.Count; ++i)
            {
                CodeExpression argExpr = invokeExpr.Parameters[i];

                if (!attributedExprs.Contains(argExpr))
                {
                    // Similar to the target object, we assume that this method can reads the value
                    // of the parameter, but none of its members.
                    RuleExpressionWalker.AnalyzeUsage(analysis, argExpr, true, false, null);
                }
            }
        }
        internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
        {
            string message;

            CodePropertyReferenceExpression propGetExpr = (CodePropertyReferenceExpression)expression;

            // Evaluate the target object and get its type.
            CodeExpression targetObject = propGetExpr.TargetObject;
            RuleExpressionInfo targetExprInfo = analysis.Validation.ExpressionInfo(targetObject);
            if (targetExprInfo == null)  // Oops, someone forgot to validate.
            {
                message = string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated);
                InvalidOperationException exception = new InvalidOperationException(message);
                exception.Data[RuleUserDataKeys.ErrorObject] = targetObject;
                throw exception;
            }

            // Get the property info from the validator so we can look for [RuleRead] and [RuleWrite] attributes.
            RulePropertyExpressionInfo propExprInfo = analysis.Validation.ExpressionInfo(propGetExpr) as RulePropertyExpressionInfo;
            if (propExprInfo == null)  // Oops, someone forgot to validate.
            {
                message = string.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated);
                InvalidOperationException exception = new InvalidOperationException(message);
                exception.Data[RuleUserDataKeys.ErrorObject] = propGetExpr;
                throw exception;
            }

            PropertyInfo pi = propExprInfo.PropertyInfo;

            // Look for RuleAttribute's on the invoked property.
            List<CodeExpression> attributedExprs = new List<CodeExpression>();
            analysis.AnalyzeRuleAttributes(pi, targetObject, qualifier, null, null, attributedExprs);

            // See if the target object needs default analysis.
            if (!attributedExprs.Contains(targetObject))
            {
                // The property had no [RuleRead] or [RuleWrite] attributes.  Just qualify the target object with
                // the property name and proceed with the analysis.
                RuleExpressionWalker.AnalyzeUsage(analysis, targetObject, isRead, isWritten, new RulePathQualifier(pi.Name, qualifier));
            }
        }