refactoring: convert class with auto-properties to record syntax
See original GitHub issueThis issue has been moved from a ticket on Developer Community.
It would be nice to have a refactoring option to convert a class with auto-properties to the new c# 9 record. For example, take the following class –
public class Foo
{
public string Bar {get;set;}
public int Baz {get;set;}
}
and convert it to
public record Foo(string Bar, int Baz);
Original Comments
Feedback Bot on 9/3/2020, 02:11 AM:
Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. We’ll provide an update once the issue has been triaged by the product team.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:60
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Convert type to record :: MappingGenerator Documentation
⭐ Convert type to record · You can choose which properties should be moved to main constructor (positional syntax) or converted to init-only...
Read more >Convert Property to Auto-Property refactoring - ReSharper
This refactoring helps you convert properties with private backing fields into auto-implemented properties (also known as auto-properties).
Read more >Refactor C# automatic properties to fields and getter/setter ...
If all of your business classes are simply classes with autoproperties and nothing else, I would convert to using T4 templates to generate...
Read more >Convert Property to Method(s) refactoring | ReSharper ...
This refactoring converts get and set accessors of properties into the corresponding methods and updates usages of the property accordingly ...
Read more >What is the purpose of using auto-properties over just a ...
Later on, if you need to add validation to the setter, you can change the auto property to the full property syntax with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This would be super useful. I have a codebase with many immutable DTOs (commands and events) that I’d like to convert into records for a more concise syntax. Having to do it all manually is a daunting task.
If anyone is still interested in this refactoring, it might be worth taking a look at the
Convert type to record
refactoring from MappingGenerator package https://docs.mappinggenerator.net/refactorings/convert-type-to-record/DISCLAIMER: it belongs to paid features