The other way arround

Oct 25, 2012 at 7:47 AM
Edited Oct 25, 2012 at 7:52 AM

 

Hi, is there a ToString() function or something like that that would enable a reverse proccess if you need to generate parameters to pass them to a calling command?

class Options
{
  [Option("i", "input", Required = true, HelpText = "Input file to read.")]
  public string InputFile { get; set; }

  [Option("l", "lenght", DefaultValue = -1, HelpText = "The maximum number of bytes to process.")]
  public int MaximumLenght { get; set; };
}
var o = new Options(){InputFile ="test.txt",MaximumLength=5};
console.writeline(o.GetParameters()); // Returns "-i test.txt -l 5" and throws an exception if InputFile is null or empty
Coordinator
Feb 24, 2013 at 5:10 AM
@jernejg,
thank you for writing and your interest.

Sorry,
but actually this is not included.

For this and other scenario I've scheduled a secondary (in term of size) project to do that.

It will be able to this and another thing split argument as OS does (and it's not String.Split).

Or maybe that the feature you describe will fall into the mainstream project.

When? As I wrote in the last post I replied. For last-moment news, follow me on Twitter: @gsscoder

Giacomo
Oct 31, 2014 at 2:57 AM
Hi there, for what it's worth I'd like to add another vote for this feature.

The use case is to store the argument string for a Scheduled Task in Windows.

Program A -> creates a Scheduled Task that will execute Program B and pass a string of commandline arguments
Program B -> uses CommandLine to parse incoming args.

By including the Options class and CommandLine library in Program A as well we can ensure our design automatically remains compatible at both ends.