Beispiel #1
0
            SearchRequest Parse(string input)
            {
                string[] parts = NativeMethods.CommandLineToArgumentArray(input);

                SearchRequest request  = new SearchRequest();
                List <string> keywords = new List <string>();
                Regex         regex    = null;

                request.Mode = searchMode;

                foreach (string part in parts)
                {
                    // Parse: [prefix:|@]["]searchTerm["]
                    // Find quotes used for escaping
                    int prefixLength = part.IndexOfAny(new[] { '"', '/' });
                    if (prefixLength < 0)
                    {
                        // no quotes
                        prefixLength = part.Length;
                    }

                    int delimiterLength;
                    // Find end of prefix
                    if (part.StartsWith("@", StringComparison.Ordinal))
                    {
                        prefixLength    = 1;
                        delimiterLength = 0;
                    }
                    else
                    {
                        prefixLength    = part.IndexOf(':', 0, prefixLength);
                        delimiterLength = 1;
                    }
                    string prefix;
                    if (prefixLength <= 0)
                    {
                        prefix       = null;
                        prefixLength = -1;
                    }
                    else
                    {
                        prefix = part.Substring(0, prefixLength);
                    }

                    // unescape quotes
                    string searchTerm = part.Substring(prefixLength + delimiterLength).Trim();
                    if (searchTerm.Length > 0)
                    {
                        searchTerm = NativeMethods.CommandLineToArgumentArray(searchTerm)[0];
                    }

                    if (prefix == null || prefix.Length <= 2)
                    {
                        if (regex == null && searchTerm.StartsWith("/", StringComparison.Ordinal) && searchTerm.Length > 1)
                        {
                            int searchTermLength = searchTerm.Length - 1;
                            if (searchTerm.EndsWith("/", StringComparison.Ordinal))
                            {
                                searchTermLength--;
                            }

                            request.FullNameSearch |= searchTerm.Contains("\\.");

                            regex = CreateRegex(searchTerm.Substring(1, searchTermLength));
                        }
                        else
                        {
                            request.FullNameSearch |= searchTerm.Contains(".");
                            keywords.Add(searchTerm);
                        }
                        request.OmitGenerics |= !(searchTerm.Contains("<") || searchTerm.Contains("`"));
                    }

                    switch (prefix?.ToUpperInvariant())
                    {
                    case "@":
                        request.Mode = SearchMode.Token;
                        break;

                    case "INNAMESPACE":
                        request.InNamespace ??= searchTerm;
                        break;

                    case "INASSEMBLY":
                        request.InAssembly ??= searchTerm;
                        break;

                    case "A":
                        request.AssemblySearchKind = AssemblySearchKind.NameOrFileName;
                        request.Mode = SearchMode.Assembly;
                        break;

                    case "AF":
                        request.AssemblySearchKind = AssemblySearchKind.FilePath;
                        request.Mode = SearchMode.Assembly;
                        break;

                    case "AN":
                        request.AssemblySearchKind = AssemblySearchKind.FullName;
                        request.Mode = SearchMode.Assembly;
                        break;

                    case "N":
                        request.Mode = SearchMode.Namespace;
                        break;

                    case "TM":
                        request.Mode             = SearchMode.Member;
                        request.MemberSearchKind = MemberSearchKind.All;
                        break;

                    case "T":
                        request.Mode             = SearchMode.Member;
                        request.MemberSearchKind = MemberSearchKind.Type;
                        break;

                    case "M":
                        request.Mode             = SearchMode.Member;
                        request.MemberSearchKind = MemberSearchKind.Member;
                        break;

                    case "MD":
                        request.Mode             = SearchMode.Member;
                        request.MemberSearchKind = MemberSearchKind.Method;
                        break;

                    case "F":
                        request.Mode             = SearchMode.Member;
                        request.MemberSearchKind = MemberSearchKind.Field;
                        break;

                    case "P":
                        request.Mode             = SearchMode.Member;
                        request.MemberSearchKind = MemberSearchKind.Property;
                        break;

                    case "E":
                        request.Mode             = SearchMode.Member;
                        request.MemberSearchKind = MemberSearchKind.Event;
                        break;

                    case "C":
                        request.Mode = SearchMode.Literal;
                        break;

                    case "R":
                        request.Mode = SearchMode.Resource;
                        break;
                    }
                }

                Regex CreateRegex(string s)
                {
                    try
                    {
                        return(new Regex(s, RegexOptions.Compiled));
                    }
                    catch (ArgumentException)
                    {
                        return(null);
                    }
                }

                request.Keywords            = keywords.ToArray();
                request.RegEx               = regex;
                request.SearchResultFactory = new SearchResultFactory(language);
                request.TreeNodeFactory     = new TreeNodeFactory();
                request.DecompilerSettings  = new DecompilationOptions().DecompilerSettings;

                return(request);
            }
        public MetadataTokenSearchStrategy(Language language, ApiVisibility apiVisibility, SearchRequest request,
                                           IProducerConsumerCollection <SearchResult> resultQueue)
            : base(language, apiVisibility, request, resultQueue)
        {
            var terms = request.Keywords;

            if (terms.Length == 1)
            {
                int.TryParse(terms[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var token);
                searchTermToken = MetadataTokenHelpers.EntityHandleOrNil(token);
            }
        }
 public ResourceSearchStrategy(ApiVisibility apiVisibility, SearchRequest request, IProducerConsumerCollection <SearchResult> resultQueue)
     : base(request, resultQueue)
 {
     this.apiVisibility = apiVisibility;
     this.searchInside  = true;
 }
Beispiel #4
0
 public MemberSearchStrategy(Language language, ApiVisibility apiVisibility, SearchRequest searchRequest,
                             IProducerConsumerCollection <SearchResult> resultQueue, MemberSearchKind searchKind = MemberSearchKind.All)
     : base(language, apiVisibility, searchRequest, resultQueue)
 {
     this.searchKind = searchKind;
 }