c#中将类转换为记录的快捷方式

问题描述 投票:0回答:3

如果我有以下课程:

public class Foo
{
    public string Code { get; set; }
    public string Description { get; set; }
    public DateTime? EffectiveDate { get; set; }
}

我想快速将其转换为

record
类型:

public record Foo(string Code, string Description, DateTime? EffectiveDate);

有没有办法快速做到这一点? VS19 中内置的快速操作菜单似乎没有提供此功能。

c# visual-studio-2019 c#-record-type
3个回答
3
投票

dotnet 开发人员正在根据此问题进行研究 classtorecode


0
投票

MappingGenerator 插件(适用于 VisualStudio 和 Rider)包含“将类型转换为记录”重构 https://docs.mappinggenerator.net/refactorings/convert-type-to-record/

免责声明:我是 MappingGenerator 的作者。上述重构属于付费功能。


0
投票

您可以在 VS 2022 中单击类别,然后单击左侧的螺丝刀后尝试“转换为位置记录”。

© www.soinside.com 2019 - 2024. All rights reserved.