gpt4 book ai didi

c# - 无法将选项转换为 System.Type on Parser.ParseArguments

转载 作者:太空狗 更新时间:2023-10-30 01:13:30 24 4
gpt4 key购买 nike

我正在尝试在项目中编译以下代码

...

namespace Buzzbox
{
class Program
{

//Command line options through CommandLine: http://commandline.codeplex.com/
class Options
{
[Option('i', "input",
Required = true,
HelpText = "Path to input file to be Encoded, must be in hearthstonejson format.")]
public string InputFile { get; set; }

[Option('o', "output",
HelpText = "Output file path.",
Default = "output.txt")]
public string OutputFile { get; set; }

[Option('e', "encoding",
HelpText = "Which encoding format to use. Supported formats are scfdivineFormat and MtgEncoderFormat.",
Default = EncodingFormats.MtgEncoderFormat)]
public EncodingFormats EncodingFormat { get; set; }

[Option("shuffle-fields", Default = false,
HelpText = "Shuffles the fields of the output in supported Encoding Formats.")]
public bool ShuffleFields { get; set; }

[Option("shuffle-cards", Default = false,
HelpText = "Shuffles the the cards, randomizing the order of output.")]
public bool ShuffleCards { get; set; }

[Option("flavor-text", Default = false,
HelpText = "Include flavortext field.")]
public bool FlavorText { get; set; }

[Option("verbose", Default = false,
HelpText = "Output additional information. Exclusive with the --silent option.")]
public bool Verbose { get; set; }

[Option("silent", Default = false,
HelpText = "Never output anything but error messages. Exclusive with the --verbose option.")]
public bool Silent { get; set; }

}

private static void Main(string[] args)
{
//Parse Commandline options
var options = new Options();
var encode = new Encode
{
ShuffleFields = options.ShuffleFields,
IncludeFlavorText = options.FlavorText
};

//Only continue if commandline options fullfilled. CommandLine will handle helptext if something was off.
if (CommandLine.Parser.Default.ParseArguments(args,options))
{
//extra things

}
}
}
}

但我似乎只是让它工作,因为这一行有错误

CommandLine.Parser.Default.ParseArguments(args,options)

异常抛出

Cannot convert from 'Buzzbox.Program.Options' to 'System.Type'

它不允许我强制转换它,我还没有找到任何解决这个问题的方法,尽管我觉得解决方案可能相当简单,因为我发现其他人提到它就像你可以转换就像这段代码一样没有任何问题,就像这里一样

http://simontimms.com/2014/07/09/parsing-command-line-arguments-in-c/

最佳答案

所以我显然在最新版本的命令行解析器应用程序中进行了一些挖掘,它要求您按如下方式执行操作。

CommandLine.Parser.Default.ParseArguments<Options>(args)  
.WithParsed<Options>(opts => options = opts);

我也很生气地找到了正确的方法来做到这一点。

关于c# - 无法将选项转换为 System.Type on Parser.ParseArguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50143730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com