public static CreateGuidOptions Parse(IEnumerable <string> arguments) { var parms = new CreateGuidOptions(); var options = new OptionSet() .Add("f=|format", f => parms.Format = (GuidFormat)Enum.Parse(typeof(GuidFormat), f)) .Add("o=|outfile", o => parms.OutFile = o) .Add("n=|num", n => parms.Count = Convert.ToUInt32(n)) .Add("?|help", p => ShowHelp()); options.Parse(arguments); return(parms); }
public static CreateGuidOptions Parse(IEnumerable<string> arguments) { var parms = new CreateGuidOptions(); var options = new OptionSet() .Add("f=|format", f => parms.Format = (GuidFormat)Enum.Parse(typeof(GuidFormat), f)) .Add("o=|outfile", o => parms.OutFile = o) .Add("n=|num", n => parms.Count = Convert.ToUInt32(n)) .Add("?|help", p=> ShowHelp()); options.Parse(arguments); return parms; }
private static string CreateGuids(CreateGuidOptions options) { using (var sw = new StringWriter()) { for (int ii = 0; ii < options.Count; ++ii) { string guid = Guid.NewGuid().ToString(options.Format.ToString()).ToUpper(); if (options.Count == 1) { sw.Write(guid); } else { sw.WriteLine(guid); } } return sw.ToString(); } }
private static string CreateGuids(CreateGuidOptions options) { using (var sw = new StringWriter()) { for (int ii = 0; ii < options.Count; ++ii) { string guid = Guid.NewGuid().ToString(options.Format.ToString()).ToUpper(); if (options.Count == 1) { sw.Write(guid); } else { sw.WriteLine(guid); } } return(sw.ToString()); } }
static void Main(string[] args) { try { var options = CreateGuidOptions.Parse(args); var guids = CreateGuids(options); if (String.IsNullOrWhiteSpace(options.OutFile)) { CopyToClipboard(guids); } else { SendToFile(guids, options); } } catch (Exception ex) { Console.WriteLine(ex); Environment.Exit(1); } }
private static void SendToFile(string guids, CreateGuidOptions options) { File.WriteAllText(options.OutFile, guids); }