Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());

            var checkValue = new ConditionalLogic(N);

            Console.WriteLine(checkValue.resultValue());

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        private static string BuildFilterExpresion <TEntity>(FilterInfo activeFilter, ConditionalLogic parentLogic, string[] multipleValuePropertyNames)
        {
            // build inner expression string

            string innerExpression = null;

            if (activeFilter.Filters != null)
            {
                foreach (var innerFilter in activeFilter.Filters)
                {
                    var expression = BuildFilterExpresion <TEntity>(innerFilter, innerFilter.Logic, multipleValuePropertyNames);

                    if (innerExpression == null)
                    {
                        innerExpression = expression;
                    }
                    else
                    {
                        innerExpression = string.Format("{0} {1} {2}",
                                                        innerExpression,
                                                        activeFilter.Logic == ConditionalLogic.And ? "&&" : "||",
                                                        expression);
                    }
                }
            }

            // if the active expression is the root expression, then the field, operator and value will be undefined - so, simply return the inner expressions
            // inner expression will not be empty or null in this case

            if (string.IsNullOrWhiteSpace(activeFilter.Field))
            {
                return(innerExpression);
            }

            // build active expression

            string activeExpression = null;

            if (multipleValuePropertyNames != null && multipleValuePropertyNames.Contains(activeFilter.Field))             // multiple values
            {
                activeExpression = BuildExpression <TEntity>(activeFilter.Field, activeFilter.FieldExpression, activeFilter.Operator,
                                                             activeFilter.Value, multipleValuePropertyNames);
            }
            else             // single value
            {
                activeExpression = BuildExpression <TEntity>(activeFilter.Field, activeFilter.FieldExpression, activeFilter.Operator,
                                                             activeFilter.Value);
            }

            // return combined expression

            if (string.IsNullOrWhiteSpace(innerExpression))
            {
                return(activeExpression);                // return active expression if inner expression is null or empty
            }
            else
            {
                return(string.Format("({0}) {1} ({2})",
                                     activeExpression,
                                     parentLogic == ConditionalLogic.And ? "&&" : "||",
                                     innerExpression));
            }
        }