Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error CS0029 Cannot implicitly convert type 'CommandLine.ParserResult<Options>' to 'Options' #511

Closed
Bluscream opened this issue Sep 22, 2019 · 5 comments

Comments

@Bluscream
Copy link

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; }
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Logger.Debug("Program started");
            Arguments = Parser.Default.ParseArguments<Options>(args);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Main());
            Logger.Debug("Program ended");
        }
    }
}
@moh-hassan
Copy link
Collaborator

modify:

      public static Options Arguments;

to

     public static ParserResult<Options> Arguments;

@Bluscream
Copy link
Author

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

@IB38
Copy link

IB38 commented Sep 25, 2019

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

@moh-hassan
Copy link
Collaborator

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;

@Bluscream
Copy link
Author

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants