How to use Option<T>?

Aug 9, 2011 at 4:23 PM

I've got an option defined as:

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 4: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:

    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 10:07 AM


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();

		var options = handler.Parse(args);

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


Hope that helps.

Kind regards,