Reporter | Andrey Zakharov (Andrey.Zakharov) |
---|---|
Created | Feb 9, 2012 12:36:54 PM |
Updated | Feb 9, 2012 3:01:12 PM |
Resolved | Feb 9, 2012 3:01:12 PM |
Priority | Normal |
Type | Feature |
Fix versions | No Fix versions |
State | Won't fix |
Assignee | Sergey Shkredov (serjic.shkredov) |
Subsystem | Refactoring |
Affected versions | No Affected versions |
Fixed in build | No Fixed in build |
It would be good to have a refactoring option to generate simple class based on anonymous class declaration. For example I have following code generationg JSON result in ASP.NET MVC controller:
For some reason (personally I got to the point when I needed IEqualityComarer implementation) I decide not to use anonymous types anymore and create a named class instead. It would be nice if resharper let me do this in one click.
Or even better if refactoring option takes in account anonymous nesting (or even giving contol over it to user):
And the final proposal is to give an option to generate contructor for abovementioned classes:
return Json(new{ SomeField="SomeValue", SomeOtherField=new[]{1,2,3}, SomeIncapsulatedAnonymous=new{ExtraField="abc"} });
For some reason (personally I got to the point when I needed IEqualityComarer implementation) I decide not to use anonymous types anymore and create a named class instead. It would be nice if resharper let me do this in one click.
return Json(new JsonViewModel{ SomeField="SomeValue", SomeOtherField=new[]{1,2,3}, SomeIncapsulatedAnonymous=new{ExtraField="abc"} }); ..... internal class JsonViewModel{ public string SomeField; public IEnumerable<int> SomeOtherField; public object SomeIncapsulatedAnonymous; }
Or even better if refactoring option takes in account anonymous nesting (or even giving contol over it to user):
return Json(new JsonViewModel{ SomeField="SomeValue", SomeOtherField=new[]{1,2,3}, SomeIncapsulatedAnonymous=new JsonSomeIncapsulatedAnonymousViewModel{ExtraField="abc"} }); ..... internal class JsonViewModel{ public string SomeField; public IEnumerable<int> SomeOtherField; public JsonSomeIncapsulatedAnonymousViewModel SomeIncapsulatedAnonymous; } internal class JsonSomeIncapsulatedAnonymousViewModel{ public string ExtraField; }
And the final proposal is to give an option to generate contructor for abovementioned classes:
return Json(new JsonViewModel("SomeValue",new[]{1,2,3},new JsonSomeIncapsulatedAnonymousViewModel("abc"))); ..... internal class JsonViewModel{ public string SomeField; public IEnumerable<int> SomeOtherField; public JsonSomeIncapsulatedAnonymousViewModel SomeIncapsulatedAnonymous; public JsonViewModel(string someField,IEnumerable<int> someOtherField,JsonSomeIncapsulatedAnonymousViewModel someIncapsulatedAnonymous){ SomeField=someField; .... } } internal class JsonSomeIncapsulatedAnonymousViewModel{ public string ExtraField; public JsonSomeIncapsulatedAnonymousViewModel(string extraField){ ExtraField=extraField } }