예제 #1
0
        private void GetExpressionHelp(string command, ref CommandHelp help)
        {
            int paramStart = command.IndexOf('(');
            int paramEnd = command.IndexOf(')');

            if (paramStart == -1)
            {
                if (!AppendDefinition(command, ref help))
                {
                    string validType = help.ValidType;
                    help.PossibleCommands = _help.Keys.Where(
                        n => n.StartsWith(command, StringComparison.InvariantCultureIgnoreCase)
                            && (validType == null || validType == GetReturnType(n))
                    ).ToArray();
                    help.TabStart = help.Command.LastIndexOf(command, StringComparison.Ordinal);
                }
            }
            else
            {
                var def = command.Substring(0, paramStart);
                AppendDefinition(def, ref help);
                FindParameterHelp(def, command.Substring(paramStart), ref help);
            }
        }
예제 #2
0
 private bool AppendDefinition(string item, ref CommandHelp commandHelp)
 {
     if (_help.ContainsKey(item))
     {
         var i = _help[item];
         commandHelp.Definitions += i.Definition + "\n";
         commandHelp.Description = i.Description;
         if (_options.ContainsKey(item))
         {
             commandHelp.Description += string.Format("\n\"{0}\"", _options[item].Property.GetValue(_options[item].Target, null));
             commandHelp.ValidType = "";
         }
         return true;
     }
     return false;
 }
예제 #3
0
        private void FindParameterHelp(string command, string parameters, ref CommandHelp help)
        {
            int brackets = 0;
            int paramStart = 1;
            int paramIndex = 0;
            for (int i = 0; i < parameters.Length; i++)
            {
                char c = parameters[i];
                if (c == '(')
                    brackets++;
                else if (c==')')
                    brackets--;
                else if (c == ',' && brackets == 1)
                {
                    paramStart = i + 1;
                    paramIndex++;
                }
            }

            if (brackets > 0)
            {
                if (_commands.ContainsKey(command))
                {
                    var p = _commands[command].Command.GetParameters();
                    if (p.Length > paramIndex)
                        help.ValidType = p[paramIndex].ParameterType.Name;
                    else
                        help.ValidType = "";
                }
                GetExpressionHelp(parameters.Substring(paramStart).Trim(), ref help);
            }
        }
예제 #4
0
        /// <summary>
        /// Gets intellisense-like help for a command.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public CommandHelp GetHelp(string command)
        {
            CommandHelp help = new CommandHelp {Command = command, Definitions = "", Description = "", PossibleCommands = new string[0]};

            int equals = command.IndexOf('=');
            if (equals > 0)
            {
                string firstIdentifier = command.Substring(0, @equals).Trim();
                AppendDefinition(firstIdentifier, ref help);
                if (_options.ContainsKey(firstIdentifier))
                    help.ValidType = _options[firstIdentifier].Property.PropertyType.Name;
                command = command.Substring(equals + 1);
            }

            //if (command.Length > 0)
                GetExpressionHelp(command.Trim(), ref help);

            return help;
        }