Response类:
using System; using System.Collections.Generic; using System.Runtime.Serialization; namespace ConsoleApplication1 { [DataContract] [Serializable] public class Response { [DataMember] public string MessageKey { get; set; } [DataMember] public bool IsSuccess { get; set; } } [DataContract] [Serializable] public class Response<T> : Response { [DataMember] public T Item { get; set; } } [DataContract] [Serializable] public class ListResponse<T> : Response { [DataMember] public List<T> Items { get; set; } } }
用法:
public Response<List<xxxBE>> Getxxx(int a, Guid b) { //············ //············ Response<List<xxxBE>> xxxBEResponseList = new Response<List<xxxBE>>(); List<xxxBE> xxxBEList = new List<xxxBE>(); try { //············ //············ foreach (var item in XXOO) { //············ //············ xxxBE xxx = new xxxBE(); //············ //············ xxxBEList.Add(xxx); } xxxBEResponseList.MessageKey = "Get XXX Succeed"; xxxBEResponseList.Item = xxxBEList; xxxBEResponseList.IsSuccess = true; } catch (Exception e) { xxxBEResponseList.MessageKey = "Get XXX Failed"; xxxBEResponseList.Item = null; xxxBEResponseList.IsSuccess = false; } return xxxBEResponseList; }