Commandline: Error CS0029 Cannot implicitly convert type 'CommandLine.ParserResult<Options>' to 'Options'

Created on 22 Sep 2019  路  5Comments  路  Source: commandlineparser/commandline

```c#
using CommandLine;
using System;
using System.Windows.Forms;

namespace MWR_Config_Editor
{
static class Program
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
public static Options Arguments;
public class Options
{
[Option('c', "console", Required = false, HelpText = "Enable console")]
public bool Verbose { get; set; }
}
///


/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
Logger.Debug("Program started");
Arguments = Parser.Default.ParseArguments(args);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main());
Logger.Debug("Program ended");
}
}
}
```

Most helpful comment

The [Pr #634) exposes The Parsed option Value to the base class, available in develop branch and will be released in v2.9.
You can:

var result = Parser.Default.ParseArguments<Options>(args);
Arguments = result.Value;

All 5 comments

modify:

      public static Options Arguments;

to

     public static ParserResult<Options> Arguments;

And how am i supposed to access the variables inside it then? ParserResult does not contain a instance of Options

You need to use WithParsed, something like:
Parser.Default.ParseArguments<Options>(args).WithParsed(result => Arguments = result);

The [Pr #634) exposes The Parsed option Value to the base class, available in develop branch and will be released in v2.9.
You can:

var result = Parser.Default.ParseArguments<Options>(args);
Arguments = result.Value;

Thanks :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TheNybbler picture TheNybbler  路  3Comments

ppumkin picture ppumkin  路  4Comments

ericnewton76 picture ericnewton76  路  3Comments

ericnewton76 picture ericnewton76  路  4Comments

moh-hassan picture moh-hassan  路  3Comments