andrew4582

CommandLineBuilder

Mar 19th, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Text;
  3.  
  4. namespace AspnetRegsqlHelper {
  5.  
  6.     public class CommandLineBuilder:List<string> {
  7.         public const string CMD_PREFIX = "-";
  8.         public const string CMD_SUFFIX = " ";
  9.         public const string COMMAND_FORMAT_EMPTY = " -{0} ";
  10.         public const string COMMAND_FORMAT = " -{0} {1} ";
  11.         public new void Add(string command) {
  12.             base.Add(this.FormatCommand(command));
  13.         }
  14.         public void Add(string command,bool noformat) {
  15.             if(!noformat)
  16.                 base.Add(this.FormatCommand(command));
  17.             else
  18.                 base.Add(command);
  19.         }
  20.         public void Add(string command,string value) {
  21.             base.Add(this.FormatCommand(command,value));
  22.         }
  23.         public new void AddRange(IEnumerable<string> collection) {
  24.             foreach(string command in collection) {
  25.                 this.Add(command);
  26.             }
  27.         }
  28.         public string FormatCommand(string command) {
  29.             return string.Format(COMMAND_FORMAT_EMPTY,command);
  30.         }
  31.         public string FormatCommand(string command,string value) {
  32.             return string.Format(COMMAND_FORMAT,command,value);
  33.         }
  34.         public string Build() {
  35.             StringBuilder sb = new StringBuilder();
  36.             foreach(string formattedCommand in base.ToArray())
  37.                 sb.Append(formattedCommand);
  38.             return sb.ToString();
  39.         }
  40.         public override string ToString() {
  41.             return Build();
  42.         }
  43.     }
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment