Shortcut to create parameterized constructor

3

Is there any shortcut in Visual Studio, which creates a constructor, with all the attributes created in the class?

class Alimento
{
    public int ID { get; set; }
    public string Titulo { get; set; }
    public string SubTitulo { get; set; }        
    public string Conteudo  { get; set; }        
    public string Filtro { get; set; }
    public DateTime DataCriacao { get; set; }
    public string NomeImagem { get; set; }
    public string DicasCuriosidades { get; set; }      
    public string Umidade  { get; set; }
    public string Energia_kcal { get; set; }
    public string Proteina_g { get; set; }
    public string Lipideos_g { get; set; }
    public string Saturados_g { get; set; }
    public string Mono_insaturados_g  { get; set; }
    public string Poli_insaturados_g  { get; set; }
    public string Colesterol_mg { get; set; }
    public string Carbo_idrato_g { get; set; }
    public string fibra_alimentar_g  { get; set; }
    public string Calcio_mg { get; set; }
    public string Magnesio_mg { get; set; }
    public string Manganes_mg { get; set; }
    public string Fosforo_mg { get; set; }
    public string Ferro_mg { get; set; }
    public string Sodio_mg { get; set; }
    public string Potassio_mg { get; set; }
    public string Zinco_mg  { get; set; }
    public string Retinol_mcg  { get; set; }
    public string Re_mcg  { get; set; }
    public string Rae_mcg { get; set; }
    public string Tiamina_mg  { get; set; }                                                                                                                                                                     
    public string Riboflavina_mg  { get; set; }
    public string Piridoxina_mg  { get; set; }
    public string Niacina_mg  { get; set; }
    public string Vitamina_c  { get; set; }

    public Alimento(int id, string titulo, ............)
    {
        ID = id;
        Titulo = titulo;            
        ............
    }
    
asked by anonymous 07.07.2015 / 15:47

2 answers

5

As far as I know, natively does not exist, or at least did not exist. I can not state in Visual Studio 2015 that it has new code helper. There may be a plugin that does this ( this for example , I do not know if it's good).

I think the Resharper does what you want with a Alt + Ins .

I know that Visual Studio can generate the builder from its use, but it's not what you want.

Someone might do something for this since the new .Net Compiler Platform (former Roslyn) makes it much easier to parse code. There is even a Brazilian project where they are doing refactorings. If you do not find anything, and you do not know how to make one, ask people who participate in Code-Cracker to make one code generator for you.

In any case, I already notice that it is not one of these good practices to make a constructor with so many parameters. Perhaps what you should use is a code generator that creates a object initializer in your statement . The result will be essentially the same if there is no competition. Even if it does, there will hardly be problems in this case. It would create something like this:

var alimento = new Alimento(identificador, titulo) {
    SubTitulo = subtitulo,
    Conteudo = conteudo,
    ...
    ...
}

It has other implications on how you're doing, maybe you're breaking the encapsulation by creating properties for all members, but I will not get into it because it's not part of the scope of the question.

More builder information .

    
07.07.2015 / 17:32
1

ctor + TAB + TAB ) is the shortcut to the default constructor.

Do not forget to use private security using getters and setters.

Shortcut to get / set is: ( Control +. )

Selecting get / set by generating and pressing

    
07.08.2017 / 15:26