首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >System.InvalidCastException解析FluentCommandLineParser参数

System.InvalidCastException解析FluentCommandLineParser参数
EN

Stack Overflow用户
提问于 2022-06-01 08:01:42
回答 1查看 51关注 0票数 3

我尝试用Fclp解析参数,并得到以下错误:

System.InvalidCastException:“无法将”System.Reflection.RtFieldInfo“类型的对象强制转换为”System.Reflection.PropertyInfo“。

对是什么原因有什么想法吗?我传递给控制台的参数是-D 5

代码语言:javascript
复制
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);
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-01 08:27:04

ApplicationArguments类中,您有公共字段,而不是属性。尝试使它们自动实现属性(例如public int TenantId { get; set; } )。读取错误消息,这可能会起到作用。

而且,这也是他们在FluentCommandLineParser项目自己的例子中所拥有的:https://github.com/fclp/fluent-command-line-parser#usage

引文:

代码语言:javascript
复制
public class ApplicationArguments
{
   public int RecordId { get; set; }
   public bool Silent { get; set; }
   public string NewValue { get; set; }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72458318

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档