I need to do this steps:
- parse a c# .cs file
- find all public class methods who return JsonResult
- if JsonResult is created with a dynamic object, create a cs file with class definition who map dynamic object
For example from this cs code file:
public partial class HomeController: Controller
{
public JsonResult MyMethod()
{
var result = new
{
Result = false,
ErrorMessage = "Test"
};
return Json(result);
}
}
I need to produce another cs file as below:
public partial class HomeController: Controller
{
public class MyMethodResult
{
public bool Result {get;set;}
public string ErrorMessage {get;set;}
}
}
Can be done with T4 template or Roslyn?
How to convert a dynamic object to a strongly typed class definition?
Thanks