Exemplo n.º 1
0
        private string CreateFunction(
            StringExpressionFunction function, string value)
        {
            StringBuilder filter = new StringBuilder();

            _paramseters.Add(value);

            filter.Append(_filterData.ValuePropertyBindingPath);

            if (_filterData.ValuePropertyType.IsGenericType &&
                _filterData.ValuePropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                filter.Append(".Value");
            }

            _paramCounter.Increment();
            _paramCounter.Increment();

            filter.AppendFormat(".ToString().{0}(@{1}, @{2})", function, (_paramCounter.ParameterNumber - 1), (_paramCounter.ParameterNumber));

            if (function == StringExpressionFunction.IndexOf)
            {
                filter.Append(" != -1 ");
            }

            _paramseters.Add(_filterData.IsCaseSensitiveSearch
                ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase);

            return(filter.ToString());
        }
        private string createFunction(
            StringExpressionFunction function, string value)
        {
            StringBuilder filter = new StringBuilder();

            paramseters.Add(value);

            filter.Append(filterData.ValuePropertyBindingPath);

            if (filterData.ValuePropertyType.IsGenericType
                && filterData.ValuePropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
            {
                filter.Append(".Value");
            }

            paramCounter.Increment();
            paramCounter.Increment();

            filter.Append(".ToString()." + function.ToString() + "(@" + (paramCounter.ParameterNumber - 1) + ", @" + (paramCounter.ParameterNumber) + ")");

            if (function == StringExpressionFunction.IndexOf)
            {
                filter.Append(" != -1 ");
            }

            paramseters.Add(filterData.IsCaseSensitiveSearch 
                ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase);

            return filter.ToString();
        }
Exemplo n.º 3
0
        private List <string> Parse(string filterString)
        {
            if (_filterData.Type == FilterType.TextContains)
            {
                filterString = string.Format("{0}{1}{0}", WildcardAnyString, filterString);
            }

            string                   token = null;
            int                      i     = 0;
            bool                     expressionCompleted = false;
            List <string>            filter          = new List <string>();
            string                   expressionValue = String.Empty;
            StringExpressionFunction function        = StringExpressionFunction.Undefined;

            do
            {
                token = i < filterString.Length ? filterString[i].ToString() : null;

                if (token == WildcardAnyString || token == null)
                {
                    if (expressionValue.StartsWith(WildcardAnyString) && token != null)
                    {
                        function = StringExpressionFunction.IndexOf;

                        expressionCompleted = true;
                    }
                    else if (expressionValue.StartsWith(WildcardAnyString) && token == null)
                    {
                        function = StringExpressionFunction.EndsWith;

                        expressionCompleted = false;
                    }
                    else
                    {
                        function = StringExpressionFunction.StartsWith;

                        if (filterString.Length - 1 > i)
                        {
                            expressionCompleted = true;
                        }
                    }
                }

                if (token == null)
                {
                    expressionCompleted = true;
                }

                expressionValue += token;

                if (expressionCompleted &&
                    function != StringExpressionFunction.Undefined &&
                    expressionValue != String.Empty)
                {
                    string expressionValueCopy = String.Copy(expressionValue);

                    expressionValueCopy = expressionValueCopy.Replace(WildcardAnyString, String.Empty);

                    if (expressionValueCopy != String.Empty)
                    {
                        filter.Add(CreateFunction(function, expressionValueCopy));
                    }

                    function = StringExpressionFunction.Undefined;

                    expressionValue = expressionValue.EndsWith(WildcardAnyString) ? WildcardAnyString : String.Empty;

                    expressionCompleted = false;
                }

                i++;
            } while (token != null);

            return(filter);
        }
        private List <string> parse(string filterString)
        {
            string                   token = null;
            int                      i     = 0;
            bool                     expressionCompleted = false;
            List <string>            filter          = new List <string>();
            string                   expressionValue = String.Empty;
            StringExpressionFunction function        = StringExpressionFunction.Undefined;

            do
            {
                token = i < filterString.Length ? filterString[i].ToString() : null;

                if (token == WildcardAnyString || token == null)
                {
                    if (expressionValue.StartsWith(WildcardAnyString) && token != null)
                    {
                        function = StringExpressionFunction.IndexOf;

                        expressionCompleted = true;
                    }
                    else if (expressionValue.StartsWith(WildcardAnyString) && token == null)
                    {
                        function = StringExpressionFunction.EndsWith;

                        expressionCompleted = false;
                    }
                    else
                    {
                        function = StringExpressionFunction.StartsWith;

                        if (filterString.Length - 1 > i)
                        {
                            expressionCompleted = true;
                        }
                    }
                }

                if (token == null)
                {
                    expressionCompleted = true;
                }

                expressionValue += token;

                if (expressionCompleted &&
                    function != StringExpressionFunction.Undefined &&
                    !string.IsNullOrEmpty(expressionValue))
                {
                    string expressionValueCopy = String.Copy(expressionValue);

                    expressionValueCopy = expressionValueCopy.Replace(WildcardAnyString, String.Empty);

                    if (!string.IsNullOrEmpty(expressionValueCopy))
                    {
                        filter.Add(createFunction(function, expressionValueCopy));
                    }

                    function = StringExpressionFunction.Undefined;

                    expressionValue = expressionValue.EndsWith(WildcardAnyString) ? WildcardAnyString : String.Empty;

                    expressionCompleted = false;
                }

                i++;
            } while (token != null);

            return(filter);
        }