question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

refactoring: convert class with auto-properties to record syntax

See original GitHub issue

This 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:open
  • Created 3 years ago
  • Reactions:60
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
aventus13commented, Nov 6, 2021

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.

1reaction
cezarypiatekcommented, Jul 12, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found