示例#1
0
        public override object Eval(object row, object context)
        {
            object lValue = base.Left.Eval(row, context);

            if (!DataStorageHelper.IsObjectNull(lValue))
            {
                if (!(lValue is string || lValue is SqlString))
                {
                    throw InvalidExpressionException.TypeMismatchInBinop(Operator.Like, lValue.GetType(), typeof(string));
                }

                object rValue = base.Right.Eval(row, context);
                if (DataStorageHelper.IsObjectNull(rValue))
                {
                    return(DBNull.Value);
                }

                if (!(rValue is string || rValue is SqlString))
                {
                    throw InvalidExpressionException.TypeMismatchInBinop(Operator.Like, typeof(string), rValue.GetType());
                }

                string text    = lValue.ToString();
                string pattern = this.AnalizePattern(rValue.ToString());

                char[] trimChars = new char[] { ' ', '\u3000' };
                text = text.TrimEnd(trimChars);

                CompareInfo compareInfo = base.Culture.CompareInfo;
                switch (this.kind)
                {
                case match_left:
                    return(0 == compareInfo.IndexOf(text, pattern, this.compareFlags));

                case match_right:
                {
                    string text4 = pattern.TrimEnd(trimChars);
                    return(compareInfo.IsSuffix(text, text4, this.compareFlags));
                }

                case match_middle:
                    return(0 <= compareInfo.IndexOf(text, pattern, this.compareFlags));

                case match_exact:
                    return(0 == compareInfo.Compare(text, pattern, this.compareFlags));

                case match_all:
                    return(true);
                }
            }

            return(DBNull.Value);
        }
示例#2
0
        public override object Eval(object row, object context)
        {
            object obj1 = this.Left.Eval(row, context);

            if (!DataStorageHelper.IsObjectNull(obj1))
            {
                if (!(obj1 is string) && !(obj1 is SqlString))
                {
                    Guid guid = obj1 as Guid;
                }
                object obj2 = this.Right.Eval(row, context);
                if (DataStorageHelper.IsObjectNull(obj2))
                {
                    return((object)DBNull.Value);
                }
                if (!(obj2 is string) && !(obj2 is SqlString) && !(obj1 is Guid))
                {
                    throw InvalidExpressionException.TypeMismatchInBinop(Operator.Like, typeof(string), obj2.GetType());
                }
                string str     = obj1.ToString();
                string string2 = this.AnalizePattern(obj2.ToString());
                char[] chArray = new char[2] {
                    ' ', ' '
                };
                CompareInfo compareInfo = this.Culture.CompareInfo;
                switch (this.kind)
                {
                case 1:
                    return((object)(0 == compareInfo.IndexOf(str, string2, this.compareFlags)));

                case 2:
                    string suffix = string2.TrimEnd(chArray);
                    return((object)compareInfo.IsSuffix(str, suffix, this.compareFlags));

                case 3:
                    return((object)(0 <= compareInfo.IndexOf(str, string2, this.compareFlags)));

                case 4:
                    return((object)(0 == compareInfo.Compare(str, string2, this.compareFlags)));

                case 5:
                    return((object)true);
                }
            }
            return((object)DBNull.Value);
        }