在 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/