获取对象引用未设置为对象C#的实例?

时间:2018-02-18 15:35:07

标签: c# tfs azure-devops tfs-workitem

我将获取对象引用未设置为对象错误的实例
我的代码和图片附在

下面
   public class Backlogitem
        {
            public string Name { get; set; }
            public int ID { get; set; }

            public string State { get; set; }
           // public DateTime? due { get; set; }
            public int priorty { get; set; }
            public int Size { get; set; }
          //  public int effort { get; set; }
            public int StoryPoints { get; set; }
            public string DoneStatus { get; set; }
            public string StoryOwner { get; set; }
            public string Assignedto { get; set; }
            public string StoryAuthor { get; set; }
            public string IterationPath { get; set; }

        }

enter image description here values of the property

workitemlist图像
enter image description here 其余代码粘贴在这里 https://github.com/akhiljain1611/TFS/blob/master/README.md

1 个答案:

答案 0 :(得分:2)

您需要初始化列表(Issues, Tasks and PBacklog),然后才能开始向其中添加项目。我使用构造函数完成了它:

public class WorkItemViewModel
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string AssignedTo { get; set; }
    public string WorkitemType { get; set; }
    public string Priorty { get; set; }
    public string IterationPath { get; set; }
    public string State { get; set; }
    public List<TFSIssue> Issues { get; set; }
    public List<TFSTask> Tasks { get; set; }
    public List<Backlogitem> PBacklog { get; set;}

    public WorkItemViewModel()  // Added a public constructor
    {
        Issues = new List<TFSIssue>();
        Tasks = new List<TFSTask>();
        PBacklog =  new List<Backlogitem>();
    }
}