internal void Revive(string commandLineValue)
{
if (ArgRevivers.CanRevive(ArgumentType) && commandLineValue != null)
{
try
{
if (ArgumentType.IsEnum)
{
RevivedValue = ArgRevivers.ReviveEnum(ArgumentType, commandLineValue, IgnoreCase);
}
else
{
RevivedValue = ArgRevivers.Revive(ArgumentType, Aliases.First(), commandLineValue);
}
}
catch(TargetInvocationException ex)
{
if (ex.InnerException != null && ex.InnerException is ArgException)
{
ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
}
else
{
if (ArgumentType.IsEnum)
{
throw new ArgException("'" + commandLineValue + "' is not a valid value for " + Aliases.First() + ". Available values are [" + string.Join(", ", Enum.GetNames(ArgumentType)) + "]", ex);
}
else
{
throw new ArgException(ex.Message, ex);
}
}
}
catch (ArgException)
{
throw;
}
catch (Exception ex)
{
if (ex.InnerException != null && ex.InnerException is ArgException)
{
throw ex.InnerException;
}
else
{
if (ArgumentType.IsEnum) throw new ArgException("'" + commandLineValue + "' is not a valid value for " + Aliases.First() + ". Available values are [" + string.Join(", ", Enum.GetNames(ArgumentType)) + "]", ex);
else throw new ArgException(ex.Message, ex);
}
}
}
else if (ArgRevivers.CanRevive(ArgumentType) && ArgumentType == typeof(SecureStringArgument))
{
RevivedValue = ArgRevivers.Revive(ArgumentType, Aliases.First(), commandLineValue);
}
else if (commandLineValue != null && ArgRevivers.CanRevive(ArgumentType))
{
throw new ArgException("Unexpected argument '" + Aliases.First() + "' with value '" + commandLineValue + "'");
}
else if (commandLineValue != null && ArgRevivers.CanRevive(ArgumentType) == false)
{
throw new InvalidArgDefinitionException("There is no reviver for type '" + ArgumentType.Name + '"');
}
}