我有类似的定义:
[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?
答案 0 :(得分:1)
这应该有效:
returnDevelopments.AddRange(developments);