我尝试用Fclp解析参数,并得到以下错误:
System.InvalidCastException:“无法将”System.Reflection.RtFieldInfo“类型的对象强制转换为”System.Reflection.PropertyInfo“。
对是什么原因有什么想法吗?我传递给控制台的参数是-D 5
class Program
{
public class ApplicationArguments
{
public int TenantId;
public int Days;
}
static void Main(string[] args)
{
var p = new FluentCommandLineParser<ApplicationArguments>();
p.Setup(arg => arg.TenantId)
.As('T', "tenantid");
p.Setup(arg => arg.Days)
.As('D', "days")
.Required();
var result = p.Parse(args);
}发布于 2022-06-01 08:27:04
在ApplicationArguments类中,您有公共字段,而不是属性。尝试使它们自动实现属性(例如public int TenantId { get; set; } )。读取错误消息,这可能会起到作用。
而且,这也是他们在FluentCommandLineParser项目自己的例子中所拥有的:https://github.com/fclp/fluent-command-line-parser#usage
引文:
public class ApplicationArguments
{
public int RecordId { get; set; }
public bool Silent { get; set; }
public string NewValue { get; set; }
}https://stackoverflow.com/questions/72458318
复制相似问题