ConsoleShared.ConsoleMacro.Save C# (CSharp) Method

Save() public method

public Save ( string name ) : ConsoleExecuteResult
name string
return ConsoleExecuteResult
        public ConsoleExecuteResult Save(string name)
        {
            var path = Path.GetDirectoryName(name);
            if (string.IsNullOrEmpty(path)) return new ConsoleExecuteResult("invalid path");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var values = new List<string>(_commands.Count);
            var list = _commands.Keys.ToList();
            list.Sort();

            // Loop through keys.
            values.AddRange(list.Select(key => _commands[key]));

            File.WriteAllLines(name, values);
            return new ConsoleExecuteResult("Saved");
        }

Usage Example

コード例 #1
0
        public static ConsoleExecuteResult SaveMacro(string name)
        {
            if (_consoleMacro == null)
            {
                return(new ConsoleExecuteResult("Nothing to save"));
            }
            //remove the last command, since that was the 'save' command
            _consoleMacro.RemoveLast();
            var result = _consoleMacro.Save(name);

            _consoleMacro = null;
            return(result);
        }