Created
November 15, 2011 20:05
-
-
Save mteece/1368163 to your computer and use it in GitHub Desktop.
C# wrapper for responses, returning a list of objects in WCF. Useful for Ajax and JSON, uses generics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Diagnostics; | |
using System.Collections.ObjectModel; | |
using System.Runtime.Serialization; | |
/* | |
using My.Domain.Namespace; | |
[DataContract(), KnownType(typeof(ExampleObject))] | |
*/ | |
public class ListResponseObject<T> | |
{ | |
private IList<T> _data; | |
private bool _success = true; | |
private int _total; | |
private string _message; | |
[DataMember()] | |
public IList<T> data | |
{ | |
get { return _data; } | |
set { _data = value; } | |
} | |
[DataMember()] | |
public bool success | |
{ | |
get { return _success; } | |
set { _success = value; } | |
} | |
[DataMember()] | |
public int total | |
{ | |
get { return _total; } | |
set { _total = value; } | |
} | |
[DataMember()] | |
public string message | |
{ | |
get { return _message; } | |
set { _message = value; } | |
} | |
} | |
/* | |
Example method for ListResponseObject returning ExampleObject wrapped. | |
public ListResponseObject<ExampleObject> FindAll() | |
{ | |
dynamic response = new ListResponseObject<ExampleObject>(); | |
response.data = ExampleObject.FindAll(); | |
response.success = true; | |
response.message = ""; | |
response.total = response.data.Count | |
return response; | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment