kOS.Command.Get C# (CSharp) Method

Get() public static method

public static Get ( String input, kOS.ExecutionContext context ) : Command
input String
context kOS.ExecutionContext
return Command
        public static Command Get(String input, ExecutionContext context)
        {
            input = input.Trim();//.Replace("\n", " ");

            foreach (var kvp in CommandRegistry.Bindings)
            {
                Match match = Regex.Match(input, kvp.Key, RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    var command = (Command)Activator.CreateInstance(kvp.Value, match, context);
                    return command;
                }
            }

            throw new kOSException("Syntax Error.", context);
        }

Same methods

Command::Get ( String input, kOS.ExecutionContext context, int line ) : Command

Usage Example

Example #1
0
        public void Run(File file)
        {
            this.file = file;

            State = ExecutionState.WAIT;

            int lineNumber = 0;

            foreach (String line in file)
            {
                commandBuffer += line;

                string cmd;
                while (parseNext(ref commandBuffer, out cmd))
                {
                    try
                    {
                        Command cmdObj = Command.Get(cmd, this);
                        cmdObj.LineNumber = lineNumber;
                        commands.Add(cmdObj);
                    }
                    catch (kOSException e)
                    {
                        StdOut("Error on line " + lineNumber + ": " + e.Message);
                        State = ExecutionState.DONE;
                        return;
                    }
                }

                lineNumber++;
                accumulator++;
            }
        }
All Usage Examples Of kOS.Command::Get