Service stack arrayof to be removed

徘徊边缘 提交于 2020-01-15 11:23:12

问题


I have my dto defined as

[DataContract(Name = "Tuner", Namespace = "")]
public class TunerDto
{
     [DataMember(Name = "TunerName", Order = 1)]
    public string TunerName { get; set; }
}

and I am returning an array of theses which gives my XML in the body as:

 <ArrayOfTuner>
    <Tuner>
       <Name>Test1</Name>
    </Tuner>
    ...

 </ArrayOfTuner>

Is there a way of replacing ArrayOfTuner with Tuners instead?


回答1:


You should wrap your array in a class, so you can add a [CollectionDataContract] attribute to modify the serialization output:

[CollectionDataContract(ItemName = "Tuner")]
public class Tuners : List<TunerDto>
{
    public  Tuners() { }
    public  Tuners(IEnumerable<TunerDto> collection) : base(collection) { }
}


来源:https://stackoverflow.com/questions/10683732/service-stack-arrayof-to-be-removed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!