I will create a wrapper class that has both List CustomObjectand error information as another property.
public class MyCustomerInfo
{
public List<CustomObject> CustomerList { set;get;}
public string ErrorDetails { set;get;}
public MyCustomerInfo()
{
if(CustomerList==null)
CustomerList=new List<CustomObject>();
}
}
Now I will return an object of this class from my method
public MyCustomerInfo GetCustomerDetails()
{
var customerInfo=new MyCustomerInfo();
try
{
dr = SQL.Execute(sql);
if(dr != null) {
while(dr.Read()) {
CustomObject c = new CustomObject();
c.Key = dr[0].ToString();
c.Value = dr[1].ToString();
c.Meta = dr[2].ToString();
customerInfo.CustomerList.Add(c);
}
}
else
{
customerInfo.ErrorDetails="No records found";
}
}
catch(Exception ex)
{
customerInfo.ErrorDetails=ex.Message;
}
return customerInfo;
}
EDIT. , .
public class OperationStatus
{
public bool IsSuccess { set;get;}
public string ErrorMessage { set;get;}
public string ErrorCode { set;get;}
public string InnerException { set;get;}
}
public class BaseEntity
{
public OperationStatus OperationStatus {set;get;}
public BaseEntity()
{
if(OperationStatus==null)
OperationStatus=new OperationStatus();
}
}
, .
public MyCustomInfo : BaseEntity
{
public List<CustomObject> CustomerList { set;get;}
}
OperationStatus
public MyCustomInfo GetThatInfo()
{
var thatObject=new MyCustomInfo();
try
{
thatObject.OperationStatus.IsSuccess=true;
}
catch(Exception ex)
{
thatObject.OperationStatus.ErrorMessage=ex.Message;
thatObject.OperationStatus.InnerException =(ex.InnerException!=null)?ex.InnerException:"";
}
return thatObject;
}