Exemplo n.º 1
0
        public IEnumerable <T> Scan(QueryParameter <T> param)
        {
            if (!CheckParameter(param))
            {
                yield break;
            }
            var index = Dictionary;

            switch (param.Comparer.Type)
            {
            case CompareTypes.Equal:
            {
                var key = CheckNull(param.TypedValue);
                if (param.Comparer.Not)
                {
                    foreach (var entry in index)
                    {
                        if (!entry.Key.Equals(key))
                        {
                            foreach (var item in entry.Value)
                            {
                                yield return(item);
                            }
                        }
                    }
                }
                else
                {
                    if (index.TryGetValue(key, out var value) && value != null)
                    {
                        foreach (var item in value)
                        {
                            yield return(item);
                        }
                    }
                }
            }
            break;

            case CompareTypes.Greater:
            {
                var key = CheckNull(param.TypedValue);
                foreach (var entry in index)

                {
                    if (((IComparable)entry.Key).CompareTo(key) > 0)
                    {
                        foreach (var item in entry.Value)
                        {
                            yield return(item);
                        }
                    }
                }
            }
            break;

            case CompareTypes.GreaterOrEqual:
            {
                var key = CheckNull(param.TypedValue);
                foreach (var entry in index)
                {
                    if (((IComparable)entry.Key).CompareTo(key) >= 0)
                    {
                        foreach (var item in entry.Value)
                        {
                            yield return(item);
                        }
                    }
                }
            }
            break;

            case CompareTypes.Less:
            {
                var key = CheckNull(param.TypedValue);
                foreach (var entry in index)
                {
                    if (((IComparable)entry.Key).CompareTo(key) < 0)
                    {
                        foreach (var item in entry.Value)
                        {
                            yield return(item);
                        }
                    }
                }
            }
            break;

            case CompareTypes.LessOrEqual:
            {
                var key = CheckNull(param.TypedValue);
                foreach (var entry in index)
                {
                    if (((IComparable)entry.Key).CompareTo(param.TypedValue) <= 0)
                    {
                        foreach (var item in entry.Value)
                        {
                            yield return(item);
                        }
                    }
                }
            }
            break;

            case CompareTypes.Like:
            {
                var key       = CheckNull(param.TypedValue);
                var stringkey = key.ToString().Trim(new char[] { '%' });
                foreach (var entry in index)
                {
                    if (!entry.Key.Equals(entry) && (entry.Key.ToString()).IndexOf(stringkey, StringComparison.OrdinalIgnoreCase) != -1)
                    {
                        foreach (var item in entry.Value)
                        {
                            yield return(item);
                        }
                    }
                }
            }
            break;

            case CompareTypes.Is:
                if (param.Comparer.Not)
                {
                    foreach (var entry in index)
                    {
                        if (!entry.Key.Equals(NullKey))
                        {
                            foreach (var item in entry.Value)
                            {
                                yield return(item);
                            }
                        }
                    }
                }
                else
                {
                    if (index.TryGetValue(NullKey, out var value))
                    {
                        foreach (var item in value)
                        {
                            yield return(item);
                        }
                    }
                }
                break;

            case CompareTypes.In:
                var list = param.Value as IEnumerable;
                if (param.Comparer.Not)
                {
                    foreach (var entry in index)
                    {
                        if (!ListHelper.Contains(list, entry.Key))
                        {
                            foreach (var item in entry.Value)
                            {
                                yield return(item);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var inItem in list)
                    {
                        if (index.TryGetValue(CheckNull(inItem), out var value))
                        {
                            foreach (T item in value)
                            {
                                yield return(item);
                            }
                        }
                    }
                }
                break;
            }
        }