예제 #1
0
            private static void PrependSnapInNameForSameCmdletNames(CommandAndName[] cmdlets, bool completingAtStartOfLine, string quote, List <CompletionResult> results)
            {
                CommandAndName name;
                int            index       = 0;
                bool           useFullName = false;

Label_0004:
                name = cmdlets[index];
                int num2 = index + 1;

                if (num2 >= cmdlets.Length)
                {
                    AddCommandResult(name, useFullName, completingAtStartOfLine, quote, results);
                }
                else
                {
                    CommandAndName name2 = cmdlets[num2];
                    if (string.Compare(name.CommandName.ShortName, name2.CommandName.ShortName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        AddCommandResult(name, true, completingAtStartOfLine, quote, results);
                        useFullName = true;
                    }
                    else
                    {
                        AddCommandResult(name, useFullName, completingAtStartOfLine, quote, results);
                        useFullName = false;
                    }
                    index++;
                    goto Label_0004;
                }
            }
예제 #2
0
            internal static List <CompletionResult> PSv2GenerateMatchSetOfCmdlets(CompletionExecutionHelper helper, string lastWord, string quote, bool completingAtStartOfLine)
            {
                bool flag;
                List <CompletionResult> results = new List <CompletionResult>();

                if (PSv2IsCommandLikeCmdlet(lastWord, out flag))
                {
                    Exception exception;
                    helper.CurrentPowerShell.AddCommand("Get-Command").AddParameter("Name", lastWord + "*").AddCommand("Sort-Object").AddParameter("Property", "Name");
                    Collection <PSObject> collection = helper.ExecuteCurrentPowerShell(out exception, null);
                    if ((collection == null) || (collection.Count <= 0))
                    {
                        return(results);
                    }
                    CommandAndName[] cmdlets = new CommandAndName[collection.Count];
                    for (int i = 0; i < collection.Count; i++)
                    {
                        PSObject psObject = collection[i];
                        string   fullName = CmdletInfo.GetFullName(psObject);
                        cmdlets[i] = new CommandAndName(psObject, PSSnapinQualifiedName.GetInstance(fullName));
                    }
                    if (flag)
                    {
                        foreach (CommandAndName name in cmdlets)
                        {
                            AddCommandResult(name, true, completingAtStartOfLine, quote, results);
                        }
                        return(results);
                    }
                    PrependSnapInNameForSameCmdletNames(cmdlets, completingAtStartOfLine, quote, results);
                }
                return(results);
            }
예제 #3
0
            private static void AddCommandResult(CommandAndName commandAndName, bool useFullName, bool completingAtStartOfLine, string quote, List <CompletionResult> results)
            {
                string       completionText = useFullName ? commandAndName.CommandName.FullName : commandAndName.CommandName.ShortName;
                string       str2           = AddQuoteIfNecessary(completionText, quote, completingAtStartOfLine);
                CommandTypes?nullable       = SafeGetProperty <CommandTypes?>(commandAndName.Command, "CommandType");

                if (nullable.HasValue)
                {
                    string str3;
                    string listItemText = SafeGetProperty <string>(commandAndName.Command, "Name");
                    if ((((CommandTypes)nullable.Value) == CommandTypes.Cmdlet) || (((CommandTypes)nullable.Value) == CommandTypes.Application))
                    {
                        str3 = SafeGetProperty <string>(commandAndName.Command, "Definition");
                    }
                    else
                    {
                        str3 = listItemText;
                    }
                    results.Add(new CompletionResult(str2, listItemText, CompletionResultType.Command, str3));
                }
            }