Exemplo n.º 1
0
        public static bool CheckWithSelector(Dictionary <string, object> other, TQItemSelector selector)
        {
            object DVAL;
            bool   nullable;

            foreach (KeyValuePair <string, TQItemSelectorParam> rule in selector.parameters)
            {
                if (other.TryGetValue(rule.Key, out DVAL))
                {
                    if (rule.Value.ValueSet == TQItemSelectorSet.Equals)
                    {
                        if (((IComparable)rule.Value.Value)
                            .CompareTo(RepresentedModel.Convert(DVAL, RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable))) != 0)
                        {
                            return(false);
                        }
                    }
                    else if (rule.Value.ValueSet == TQItemSelectorSet.NotEquals)
                    {
                        if (((IComparable)rule.Value.Value)
                            .CompareTo(RepresentedModel.Convert(DVAL, RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable))) == 0)
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public static bool CheckWithSelector(System.Collections.Hashtable other, TQItemSelector selector)
        {
            object DVAL;
            bool   nullable;

            foreach (KeyValuePair <string, TQItemSelectorParam> rule in selector.parameters)
            {
                if (other.ContainsKey(rule.Key))
                {
                    DVAL = other[rule.Key];
                    if (rule.Value.ValueSet == TQItemSelectorSet.Equals)
                    {
                        if (((IComparable)rule.Value.Value)
                            .CompareTo(RepresentedModel.Convert(DVAL, RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable))) != 0)
                        {
                            return(false);
                        }
                    }
                    else if (rule.Value.ValueSet == TQItemSelectorSet.NotEquals)
                    {
                        if (((IComparable)rule.Value.Value)
                            .CompareTo(RepresentedModel.Convert(DVAL, RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable))) == 0)
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This will check for all required keys in dictionary and
        /// CHECK Equal or NotEqual valued parameters by selector
        /// </summary>
        /// <param name="selector"></param>
        /// <returns></returns>
        public static InternalCheckDictionary MakeCheckerDictionary(TQItemSelector selector)
        {
            Type KeyType = typeof(Dictionary <string, object>);

            ParameterExpression one = Expression.Parameter(KeyType);

            List <Expression> body = new List <Expression>();

            MethodInfo tryGetValue = KeyType.GetMethod("TryGetValue", new Type[] { typeof(string), typeof(object).MakeByRefType() });// string, out object
            MethodInfo conv        = typeof(RepresentedModel).GetMethod("Convert");

            LabelTarget         returnTarget = Expression.Label(typeof(bool));
            ParameterExpression varOut       = Expression.Variable(typeof(object), "outObject");
            bool nullable;

            foreach (KeyValuePair <string, TQItemSelectorParam> rule in selector.parameters)
            {
                Expression callOut = Expression.Call(one, tryGetValue, Expression.Constant(rule.Key), varOut);

                Expression cond = Expression.IfThen(Expression.Not(callOut), Expression.Return(returnTarget, Expression.Constant(false)));
                body.Add(cond);
                if (rule.Value.ValueSet == TQItemSelectorSet.Ascending || rule.Value.ValueSet == TQItemSelectorSet.Descending)
                {
                    continue;
                }

                Expression cmpVal      = Expression.Constant(rule.Value.Value);
                MethodInfo internalCMP = rule.Value.Value.GetType().GetMethod("CompareTo", new Type[] { typeof(object) });
                Expression ICMP        = Expression.Call(cmpVal, internalCMP, Expression.Call(null, conv, varOut, Expression.Constant(RepresentedModel.GetRType(rule.Value.Value.GetType(), out nullable))));
                Expression isEq        = null;

                if (rule.Value.ValueSet == TQItemSelectorSet.Equals)
                {
                    isEq = Expression.NotEqual(ICMP, Expression.Constant(0));
                }
                else if (rule.Value.ValueSet == TQItemSelectorSet.NotEquals)
                {
                    isEq = Expression.Equal(ICMP, Expression.Constant(0));
                }
                Expression cond2 = Expression.IfThen(isEq, Expression.Return(returnTarget, Expression.Constant(false)));
                body.Add(cond2);
            }
            LabelExpression returnDef = Expression.Label(returnTarget, Expression.Constant(true));

            body.Add(returnDef);
            Expression expression_body = Expression.Block(new[] { varOut }, body);

            return((InternalCheckDictionary)Expression.Lambda(typeof(InternalCheckDictionary), expression_body, one).Compile());
        }