コード例 #1
0
            public override object VisitMethodCallExpression(IMethodCallExpression expression)
            {
                // check if analysis of this property isn't terminated
                if (this.context.Current.PropertyAnalysisTerminated)
                {
                    return(expression);
                }

                string invocationPath;

                // if expression is property invocation chain add explicate dependency and don't analyze this branch.
                if (this.context.Current.IsInCurrentProperty() && this.TryGetPropertyInvocationChain(expression, out invocationPath))
                {
                    this.context.Current.ExplicitDependencyMap.AddDependency(this.context.Current.CurrentProperty.Name, invocationPath);
                    return(base.VisitMethodCallExpression(expression));
                }

                List <string> ivocationPaths;

                // if expression is Depends.On call add explicit dependency and terminate analysis of this property
                if (this.TryGetDependsOn(expression, out ivocationPaths))
                {
                    // Depends.On is valid only in property
                    if (this.context.Current.Parent == null || !this.context.Current.Parent.IsInCurrentProperty())
                    {
                        DomainMessageSource.Instance.Write(
                            this.context.Current.CurrentProperty,
                            SeverityType.Error,
                            "DOM012",
                            this.context.Current.CurrentMethod);
                    }

                    this.context.Current.TerminateCurrentPropertyAnalysis();
                    this.context.Current.ExplicitDependencyMap.AddDependencies(this.context.Current.CurrentProperty.Name, ivocationPaths);
                    return(expression);
                }

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

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

                this.AnalyzeMethodRecursive(expression.Method);
                IList <FieldInfo> calledMethodFields;

                this.methodFieldDependencies.TryGetValue(expression.Method, out calledMethodFields);

                if (calledMethodFields != null)
                {
                    IList <FieldInfo> fieldList = this.methodFieldDependencies.GetOrCreate(this.context.Current.CurrentMethod, () => new List <FieldInfo>());
                    foreach (FieldInfo calledMethodField in calledMethodFields)
                    {
                        fieldList.AddIfNew(calledMethodField);
                    }
                }

                return(base.VisitMethodCallExpression(expression));
            }
コード例 #2
0
        public void Constructor_SetsSuccessToTrue()
        {
            var result = new ExpressionValidationResult();
            var actual = result.Success;

            Assert.True(actual);
        }
コード例 #3
0
        public void ExceptionSetter_NotSupportedException_AddsToExceptionProperty()
        {
            var result = new ExpressionValidationResult();

            result.Exception = new NotSupportedException("TestError");
            var actual = result.Exception;

            Assert.IsType <NotSupportedException>(actual);
            Assert.Equal("TestError", actual.Message);
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: o2themar/Calculator
        void OnEqual(object sender, System.EventArgs e)
        {
            ExpressionValidationResult validationResult = ValidateExpression(display.Text);

            // If valid expression calculate
            if (validationResult.isValid)
            {
                Decimal result = CalculateResult(validationResult);
                DisplayAlert("Result: " + result, "Valid", "Close");
            }
            else
            {
                // Dispaly error
                DisplayAlert("Result", "Invalid Expression", "Close");
            }
        }
コード例 #5
0
            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));
            }
コード例 #6
0
ファイル: MainPage.xaml.cs プロジェクト: o2themar/Calculator
        private Decimal CalculateResult(ExpressionValidationResult validationResult)
        {
            Decimal[]   numbers   = validationResult.numbers;
            List <char> operators = validationResult.operators;

            Decimal num1 = numbers[0];
            Decimal num2 = numbers[1];
            Decimal num3;

            char operator1 = operators.ElementAt(0);
            char operator2;

            Decimal result = 0;

            if (numbers.Length > 2)
            {
                for (int i = 2; i < numbers.Length; i++)
                {
                    num3      = numbers[i];
                    operator2 = operators.ElementAt(i - 1);

                    if (operator2.Equals('*') ||
                        operator2.Equals('/') ||
                        operator2.Equals('%'))
                    {
                        num2 = CalculateExpression(num2, num3, operator2);
                    }
                    else
                    {
                        num1      = CalculateExpression(num1, num2, operator1);
                        num2      = num3;
                        operator1 = operator2;
                    }
                }
                result = CalculateExpression(num1, num2, operator1);
            }
            else
            {
                result = CalculateExpression(num1, num2, operator1);
            }

            return(result);
        }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: o2themar/Calculator
        private ExpressionValidationResult ValidateExpression(String expression)
        {
            string[] numbers = expression.Split(STANDARD_OPERATORS);
            numbers = numbers.Where(x => !string.IsNullOrEmpty(x)).ToArray();

            int         operatorCount = 0;
            List <char> operators     = new List <char>();

            foreach (char c in expression)
            {
                if (STANDARD_OPERATORS.Contains(c))
                {
                    operatorCount++;
                    operators.Add(c);
                }
            }

            Boolean isValidExpression         = IsValidOperators(numbers, operatorCount) && IsValidNumbers(numbers);
            ExpressionValidationResult result = new
                                                ExpressionValidationResult(isValidExpression, ConvertNumbersToFloat(numbers), operators);

            return(result);
        }
コード例 #8
0
 public ExpressionValidationResultWithErrors(ExpressionValidationResult result)
 {
     this.Result = result;
 }
コード例 #9
0
 public ExpressionValidationResultWithErrors( ExpressionValidationResult result )
 {
     this.Result = result;
 }