Created
November 2, 2011 20:07
-
-
Save mteece/1334732 to your computer and use it in GitHub Desktop.
C# wrapper for generic objects response. Useful for objects in WCF with Ajax and JSON.
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 RecordResponseObject<T> | |
{ | |
private T _data; | |
private bool _success = true; | |
private int _total; | |
private string _message; | |
[DataMember()] | |
public bool success | |
{ | |
get { return _success; } | |
set { _success = value; } | |
} | |
[DataMember()] | |
public string message | |
{ | |
get { return _message; } | |
set { _message = value; } | |
} | |
[DataMember()] | |
public T data | |
{ | |
get { return _data; } | |
set { _data = value; } | |
} | |
public RecordResponseObject(ref T data) | |
{ | |
_data = data; | |
} | |
} | |
/* | |
Example method for RecordResponseObject returning List of ExampleObject wrapped. | |
public RecordResponseObject<List<ExampleObject>> Save(List<ExampleObject> data) | |
{ | |
List<ExampleObject> response = new List<ExampleObject>(); | |
foreach (ExampleObject item in data) { | |
int id = ExampleObject.Save(item); | |
ExampleObject record = ExampleObject.Find(id); | |
response.Add(record); | |
} | |
return new RecordResponseObject<List<ExampleObject>>(response); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much.