adrianaisemberg/CLAP — Issue #8: Handling of Nullables (int?)
Author: jbattermann
Created: 2011-11-22 15:23:33+00:00
State: open

Hello there,

I have a [Verb] with two int? / nullable parameters but CLAP throws an exception in case they are actually present:

CLAP.TypeConvertionException: '1' cannot be converted to System.Nullable`1[System.Int32] ---> CLAP.TypeConvertionException: '1' cannot be converted to System.Nullable`1[System.Int32]
at CLAP.ValuesFactory.ConvertParameterValue(String inputKey, String stringValue, Type parameterType, Exception deserializationException)
at CLAP.ValuesFactory.GetValueForParameter(Type parameterType, String inputKey, String stringValue)
--- End of inner exception stack trace ---
at CLAP.ValuesFactory.ConvertParameterValue(String inputKey, String stringValue, Type parameterType, Exception deserializationException)
at CLAP.ValuesFactory.GetValueForParameter(Type parameterType, String inputKey, String stringValue)
at CLAP.ValuesFactory.CreateParameterValues(String verb, Dictionary`2 inputArgs, IEnumerable`1 list)
at CLAP.ParserRunner.RunInternal(String[] args, Object obj)
at CLAP.ParserRunner.TryRunInternal(String[] args, Object obj)
at CLAP.MultiParser.RunTargets(String[] args, Object[] targets)
at CLAP.Parser.Run[T](String[] args)

.. the static method looks like this:

[Verb(IsDefault = true, Description = "Extracts the raw html stored in the CaliberRM database")]
public static void ExtractHtml(
[Parameter(Required = true)] string hostname,
[MoreThan(0)] [Parameter(Default = 20000, Required = false)]int port,
[Parameter(Required = true)] string username,
[Parameter(Required = true)] string password,
[Parameter(Required = true)] int requirementId,
[MoreThan(0)] [Parameter(Required = false)] int? majorVersion = null,
[MoreThan(0)] [Parameter(Required = false)] int? minorVersion = null)
{
// ...
}

Is there any way to use nullables or write my own type converter for CLAP?

Cheers and thanks for this awesome little library!
-J