Is there any ready for use code snippet in VS 2010 Express edition (for C#), to create constructor with parameters from selected properties?
When I create a new class and I've written following code:
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()
{
}
}
I would like to mouse-select all the public properties (or put some snippet code), that produce following costructor for me:
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;
}
Question: is there any ready solution for that or, if no, does anyone has got an idea or ready code how to achieve that?
Best regards,
Marcin
Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Generate constructor in <QualifiedName> (with properties).
ReSharper is what you're looking for. But there's no free version. But from .NET 3.5 you can initialize the properties without having an explicit argument for each of them.
I don't believe snippets can help you with that. You would need to be able to analyze the types of the properties to generate the constructors, plus it would need to be able to convert to camel case.. snippets are basically simple substitution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With