On the return of an object I want to ensure an action is performed just before if is returned. Is there a way to override the default return of an object to perform that?
for example
//In the constructor I set a query start time
var items = new ListReturnDTO<Product>();
....
//I want to set a query end time, but without the need to set the variable in code as it could be forgotten.
return items;
EDIT:
//I set the QueryStartTime in the constructor
var items = new ListReturnDTO<Product>();
items.TotalItem = 11;
........
items.data.Add(new Product { SKU = "000006", Description = "this is the test product 7, a rare breed of product", Price = 65.00, QuantityLeft = 3, Title = "Test Product 7", IsPreview = false });
items.data.Add(new Product { SKU = "000007", Description = "this is the test product 8, a rare breed of product", Price = 7.00, QuantityLeft = 30, Title = "Test Product 8", IsPreview = false });
//force a delay to replicate talking to external source
Thread.Sleep(2000);
//Currently i set QueryEndTime Here
items.QueryEndTime = DateTime.UtcNow.TimeOfDay;
//But i want it to be done automatically on the return (like how I can set QueryStartTime in the constructor, is there an equivalent/an override for the return)
return Task.FromResult(items);