I am trying to make a class in C# that can be used to return data of any types.
public class ResponseObject { public <T> data { get;set } public Boolean Success { get; set; } public string Message { get; set; } } The Object will be a wrapper for the response object when my application sends a request to the API.
i have tried researching this but cannot find any tutorials which are relevant to what i am trying to do.
Is this possible in C#? the Response Object will be converted to a JSON string and then sent as a response.
I will not be doing any processing of this object as that will already by done. I just want to place the data inside the ResponseObject and send it
I want to do something along the lines of:
var customers = repository.GetCustomers(); var orders = repository.GetOrders(); if(customers) { success = true; message = ""; } else{ success = false; message = "failed to get customers"; } if(orders) { orderssuccess = true; ordersmessage = ""; } else{ orderssuccess = false; ordersmessage = "failed to get orders"; } ResponseObject customerResponse = new ResponseObject{ data = customers, success = success, message = message }; ResponseObject orderResponse = new ResponseObject{ data = orders, success = orderssuccess, message = ordersmessage };
GetDatainstead.