How to use Option<T>?

Aug 9, 2011 at 5:23 PM

I've got an option defined as:

[Option("dbConnectionName")]
public class DBConnectionNameSetting : Option<string>
{
}

Thinking that I may be able to access it's value as such:

var dbConnectionNameConfig = lstArgs.FindByName("dbConnectionName").SingleOrDefault();
var DBConnectionName= new DBConnectionNameSetting
handler.Mapper.MapObject(dbConnectionNameConfig, DBConnectionName);
//finally use it:
var dbConnName = DBConnectionName.Value;
 
 


But .Value is null... what am I doing wrong? I'd like to call the program like so:

myapp.exe /dbConnectionName="MyDBName" /service -endpointName="blah" -ignoreCertificateError=false

 

Aug 9, 2011 at 5:35 PM

I'm actually finding out that NONE of my settings are getting parsed correctly.. all .Value are empty strings...

Here's how I'm calling it:

StudyConsoleEngine.exe /db -connectionName="FakeName" /service -endpointName="BasicHttpBinding_IStudyService_Production" /ivr -filePath="c:\test.txt" -convertTime=true -sourceTimeZone="Central Standard Time"

and here's the code of one of my options:

 [Option("ivr")]
    public class IVRSettings : Option
    {
        [OptionParameter("filePath", Required = true)]
        public string FilePath { get; set; }

        [OptionParameter("convertTime", Required = true)]
        public bool ConvertTime { get; set; }
        
        [OptionParameter("sourceTimeZone", Required = false)]
        public string SourceTimeZone { get; set; }
    }
Aug 12, 2011 at 11:07 AM

Hi,

the option-class and the attributes are okay; the problem is the "=" sign... the commandline should look like this:

/ivr -filePath:"C:\temp\xyz.file" -convertTime:true

You can access the arguments like the following example...

class Program
{
	static void Main(string[] args)
	{
		var handler = new CommandLineHandler();

		handler.Register<IVRSettings>();
	
		var options = handler.Parse(args);

		var settings = (IVRSettings) options.FindByName("ivr").Single();

		Console.WriteLine(settings.FilePath);
	}
}

Hope that helps.

Kind regards,
Matthias