I'd like to search all the places like following where the Anonymous types in Controllers
is being used as follows.
if(success) {
returnData = JsonConvert.SerializeObject(new { Success = true, Message = "Operation completed successfully" });
}
else {
returnData = JsonConvert.SerializeObject(new { Success = false, Message = "Operation failed" });
}
In above case the returnData
is a JsonResult
and its used in our Razor
views to parse the status of the AJAX
requests.
I want to minimize the usage of Anonymous types in such case as this could be maintenance issue as compiler would not raise any warning/errors if any of the line is written as new { Succes = true, Message = "Operation completed successfully"}
and it would result into run-time error in the client-side scripts.
Any insights on restricting such situation or detecting such instances would be appreciated.