Convert type to record
⭐ Convert type to record
The C# 9 introduced record types. Some existing classes and structures can be compacted by converting them to records. However, this requires a lot of typing. MappingGenerator provides code refactoring called Convert type to record
that automates that process. It handles the following steps of converting types to records:
- Moving auto-properties to the main constructor
- Rewriting existing attributes when moving property to the main constructor
- Rewriting documentation comments when moving property to the main constructor
- Rewriting existing initialization blocks into the main constructor invocation
- Merging non-const property initialization with the call-site overrides
With a dedicated UI configurator, you can customize many aspects of that refactoring, like:
- You can choose which properties should be moved to main constructor (positional syntax) or converted to
init-only
- You can choose order or main constructor arguments.
- You can choose how to main constructor and it’s invocations are formatted.