Esempio n. 1
0
        /// <summary>
        /// Builds up an expression to compare the specified operators.
        /// </summary>
        /// <param name="current">The expression that represents the current element of the collection.</param>
        /// <param name="left">The left operand.</param>
        /// <param name="right">The right operand.</param>
        /// <returns>The operand that wraps the built expression.</returns>
        public override Operand Compare(Expression current, Operand left, Operand right)
        {
            Logger.Info("Comparing operands (left = '{0}', right = '{1}').", left.OperandType.FullName, right.OperandType.FullName);

            Expression result = null;

            if (left is BlankOperand)
            {
                var operands = new List <Operand>();

                var attr = Attribute.GetCustomAttribute(typeof(T), typeof(MetadataTypeAttribute)) as MetadataTypeAttribute;
                var type = (attr != null) ? attr.MetadataClassType : typeof(T);
                foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    if (property.CanRead && Attribute.GetCustomAttribute(property, typeof(NotEvaluateAttribute)) == null)
                    {
                        operands.Add(_builder.BuildUp(current, typeof(T).GetProperty(property.Name, BindingFlags.Instance | BindingFlags.Public)));
                        Logger.Verbose("Generated an operand with '{0}' property.", property.Name);
                    }
                    else
                    {
                        Logger.Verbose("Ignored '{0}' property.", property.Name);
                    }
                }

                if (operands.Count == 0)
                {
                    Logger.Verbose("Generated a constant true operand.");
                    return(new Operand(Expression.Constant(true), typeof(bool)));
                }

                result = Compare(operands[0], right);
                for (var i = 1; i < operands.Count; i++)
                {
                    result = Expression.Or(result, Compare(operands[i], right));
                }
            }
            else
            {
                result = Compare(left, right);
            }

            return(new Operand(result, typeof(bool)));
        }
Esempio n. 2
0
        public bool CompareShouldBeAffectedIgnoreCase(string left, string right, bool ignoreCase)
        {
            var expression = Expression.Constant("");
            var result     = new Equal <CustomEntity>("=", ignoreCase).Compare(expression, OperandBuilder.BuildUp(left), OperandBuilder.BuildUp(right));

            return((bool)Expression.Lambda(result.Expression).Compile().DynamicInvoke());
        }