ASP.NET MVC api为类分配列表

时间:2018-02-23 19:31:24

标签: asp.net asp.net-mvc asp.net-web-api

我有类似的定义:

[XmlRoot("Developments")]
public class DevelopmentsClass : List<Development> { }

在我的控制器中我有这个功能:

public DevelopmentsClass getFeed()
{

  DevelopmentsClass returnDevelopments = new DevelopmentsClass();
  List<Development> developments = new List<Development>();

  Development development = new Development();

  //A bunch of code assigning variables to development and then adding development to developments
  return returnDevelopments;

}

我的问题是,如何将开发分配给DevelopmentsClass?我不得不对XmlRoot进行此更改,我不想重写一堆代码....有没有快速的方法将开发分配给DevelopmentsClass?

1 个答案:

答案 0 :(得分:1)

这应该有效:

returnDevelopments.AddRange(developments);