Snippet code to create constructor in VS2010 Express
Asked Answered
V

3

6

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

Vivienne answered 18/10, 2011 at 15:21 Comment(5)
Have you looked into ReSharper?Laden
@Ramhound, that's what I would recommend too. But considering he is using Express edition, I doubt he has money for that. Does Resharper even work with the Express edition?Rockrose
Any version Visual Studio Express does not support add-ons, since this cannot be done with a snippet, his choices are limited to basically amounts to using another editor.Laden
AFAIK ReSharper is available as trial version, and the licence cost is too big for my company (unfortunately... I have to use Express edition for a reason). What's more, so far I just need this one, specific functionality.Vivienne
@mj82, you say that now. But if you were actually using it for some time, you would say you need many other features. I'm quite certain the investment in R# would be actually financially beneficial for your company.Rockrose
S
1

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.

Scoliosis answered 18/10, 2011 at 16:15 Comment(0)
V
1

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.

Valdez answered 18/10, 2011 at 15:23 Comment(1)
Camel casing is secondary issue, I would be happy if it repeats the properties 1:1Vivienne
S
1

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.

Scoliosis answered 18/10, 2011 at 16:15 Comment(0)
I
0

Well... I think the best solution might be to use a script of some sort. You could then run it, either from command line, or, use a separate text editor with scripting support, copy/paste the class to this second editor, run script which generates the constructor, copy/paste the constructor back to VS Express.

Say, Notepad++ with the python script plugin?

Irrelevancy answered 10/4, 2012 at 6:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.