如何初始化

时间:2014-10-03 20:59:36

标签: c# api initialization nullreferenceexception

我使用Axosoft制作的API包装器作为他们的ontime软件。我正在查看他们的API示例,该示例演示了如何使用他们的api创建项目(即var foo = axosoftClinet.Customer.Create(new Customer { //fields similar to worklogs here });)几次当我尝试其他创建方法时,他们完美无缺地工作现在我被卡住了。我的代码中出现了NullReferenceException。在阅读了堆栈溢出问题here之后,我认为我没有将WorkLog初始化。

当我开始编写调用时,它会得到这个帮助文本。

Result<WorkLog> ICreateResource<WorkLog>.Create(Worklog entity, [IDictionary<string,object> parameters = null})

帮助文本与我可以使用的所有其他项目相同。创建。我从未见过其他例子使用过IDictorynary。

所以我的问题是如何初始化WorkLog以避免NullRefenceException?

DateTime? wlDateTime = Datetime.Now;    
var worklogpost = axosoftClient.WorkLogs.Create(new WorkLog
    {
        Item =
        {
            ItemType = "defects",
            Id = 31
        },
        WorkDone =
        {
            Duration = 2,
            TimeUnit =
            {
                Id = 2
            },
        },
        User =
        {
            Id = 100
        },
        WorklogType =
        {
            Id = 1
        },
        Description = "created a worklog from the code.",
        DateTime = wlDateTime,
    });

1 个答案:

答案 0 :(得分:1)

我会尝试将它们实例化为。我可能会考虑它。

Item = new Item
        {
            ItemType = "defects",
            Id = 31
        }
相关问题