繁体   English   中英

用于在VS2010 Express中创建构造函数的代码段

[英]Snippet code to create constructor in VS2010 Express

在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()
    {
    }
}

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

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开始,您可以初始化属性,而无需为每个属性创建明确的参数。

嗯......我认为最好的解决方案可能是使用某种脚本。 然后,您可以从命令行运行它,或者使用带脚本支持的单独文本编辑器,将类复制/粘贴到第二个编辑器,运行生成构造函数的脚本,将构造函数复制/粘贴回VS Express。

说,Notepad ++与python脚本插件?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM