OleViewDotNet.COMRegistryViewer.CreateFilter C# (CSharp) Method

CreateFilter() private static method

private static CreateFilter ( string filter, int mode, bool caseSensitive ) : bool>.Func
filter string
mode int
caseSensitive bool
return bool>.Func
        private static Func<TreeNode, bool> CreateFilter(string filter, int mode, bool caseSensitive)
        {                        
            StringComparison comp;

            if(caseSensitive)
            {
                comp = StringComparison.CurrentCulture;
            }
            else
            {
                comp = StringComparison.CurrentCultureIgnoreCase;
            }

            switch (mode)
            {
                case 0:
                    if (caseSensitive)
                    {
                        return n => n.Text.Contains(filter);
                    }
                    else
                    {
                        filter = filter.ToLower();
                        return n => n.Text.ToLower().Contains(filter.ToLower());
                    }
                case 1:
                    return n => n.Text.StartsWith(filter, comp);
                case 2:
                    return n => n.Text.EndsWith(filter, comp);
                case 3:
                    return n => n.Text.Equals(filter, comp);
                case 4:
                    {
                        Regex r = GlobToRegex(filter, caseSensitive);

                        return n => r.IsMatch(n.Text);
                    }
                case 5:
                    {
                        Regex r = new Regex(filter, caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);

                        return n => r.IsMatch(n.Text);
                    }
                case 6:
                    {
                        Func<object, bool> python_filter = CreatePythonFilter(filter);

                        return n => RunPythonFilter(n, python_filter);
                    }
                default:
                    throw new ArgumentException("Invalid mode value");
            }
        }