Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Text;
- namespace AspnetRegsqlHelper {
- public class CommandLineBuilder:List<string> {
- public const string CMD_PREFIX = "-";
- public const string CMD_SUFFIX = " ";
- public const string COMMAND_FORMAT_EMPTY = " -{0} ";
- public const string COMMAND_FORMAT = " -{0} {1} ";
- public new void Add(string command) {
- base.Add(this.FormatCommand(command));
- }
- public void Add(string command,bool noformat) {
- if(!noformat)
- base.Add(this.FormatCommand(command));
- else
- base.Add(command);
- }
- public void Add(string command,string value) {
- base.Add(this.FormatCommand(command,value));
- }
- public new void AddRange(IEnumerable<string> collection) {
- foreach(string command in collection) {
- this.Add(command);
- }
- }
- public string FormatCommand(string command) {
- return string.Format(COMMAND_FORMAT_EMPTY,command);
- }
- public string FormatCommand(string command,string value) {
- return string.Format(COMMAND_FORMAT,command,value);
- }
- public string Build() {
- StringBuilder sb = new StringBuilder();
- foreach(string formattedCommand in base.ToArray())
- sb.Append(formattedCommand);
- return sb.ToString();
- }
- public override string ToString() {
- return Build();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment