c# - 在 VS2010 Express 中创建构造函数的代码片段

标签 c# visual-studio code-snippets

在 VS 2010 Express 版(C# 版)中是否有任何现成的代码片段,可以使用选定属性的参数创建构造函数?

当我创建一个新类时,我编写了以下代码:

public class FileDetails
{
    public int ID { get; set; }
    public string FileName { get; set; }
    public string FilePath { get; set; }
    public DateTime LastWriteTime { get; set; }
    public FileStatus LastFileStatus { get; set; }
    public NotifyIfFileNotExists NotifyIfFileNotExists { get; set; }
    public string RecepientsEmailList { get; set; }
    public string AdminEmailList { get; set; }

    public FileDetails()
    {
    }
}

我想用鼠标选择所有公共(public)属性(或放置一些片段代码),为我生成以下构造函数:

public FileDetails(int id, string fileName, string filePath, DateTime lastWriteTime, FileStatus lastFileStatus, NotifyIfFileNotExists notifyIfFileNotExists, string recepientsEmailList, string adminEmailList)
{
    this.ID = id;
    this.FileName = fileName;
    this.FilePath = filePath;
    this.LastWriteTime = lastWriteTime;
    this.LastFileStatus = LastFileStatus;
    this.NotifyIfFileNotExists = notifyIfFileNotExists;
    this.RecepientsEmailList = recepientsEmailList;
    this.AdminEmailList = adminEmailList;
}

问题:是否有现成的解决方案,如果没有,是否有人有想法或现成的代码如何实现?

最好的问候,
马尔辛

最佳答案

ReSharper 正是您要寻找的。但是没有免费版本。但是从 .NET 3.5 开始,您可以初始化属性,而无需为每个属性设置显式参数。

关于c# - 在 VS2010 Express 中创建构造函数的代码片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7809677/

相关文章:

c# - 为什么同步延续不再同步执行?

visual-studio - 在工作流设计器中从 VB 切换到 C#

c# - 在 C# 中,如何在单独的类中分配/编辑变量?

php - 如何在Sublime文字代码段中转义$

wordpress - 产品页面上的 WooCommerce 后退按钮

c# - 使用 vbscript 访问窗口的标题

c# - 在商业应用中使用 Fluent NHibernate

c# - 故障排除 : Why doesn't type inference fail here?

visual-studio - 在 Visual Studio 中更改宏

php - 如何在我的 wordpress 网站头部编辑不必要的 <style> 标签