Customize the comments generated with ctorp/ctorf snippets? C#

Hello,

I often write classes that have fields or properties that I want to be set from a single constructor via the parameters to that constructor. The 'ctorp' and 'ctorf' snippets are endlessly useful for exactly this.

However, when I use these snippets, the resulting constructor has a summary comment that is practically useless.

For example:

public class Coordinates
{
public decimal Latitude { get; }
public decimal Longitude { get; }

/// <summary>
/// Initializes a new instance of the <see cref="T:System.Object" /> class.
/// </summary>
public Coordinates(decimal latitude, decimal longitude)
{
Latitude = latitude;
Longitude = longitude;
}
}

I was hoping that by editing the 'ctor' Live Template that is provided by Resharper, that I could customize this. However, the ctorf and ctorp snippets do not seem to utilize those changes.

Is it possible to customize these snippets in some way? For example, my edited ctor template - which works as desired but only for generating the default constructor:

/// <summary>
/// Initializes a new instance of the <see cref="T:$namespace$.$classname$" /> class.
/// </summary>
public $classname$ ()
{
$END$
}
3 comments
Comment actions Permalink

Hello @Chris Thompson,

Thank you for contacting us! Do I get you right that you wish to get rid of the commentary above the generated constructors?

0
Comment actions Permalink

Hi Andrey Simukov,

Not quite - I suppose that is one possible use case, but I believe there is already an option that controls whether these constructor generators add comments or not, I'd have to dig to find which setting that is, though.

Really what I would like is if the comments generated didn't refer to System.Object as the type when generating a constructor comments - its not very helpful/informative. My thought is that this could be handled either by updating the existing templates/suggestions to derive the

<see cref="T:$namespace$.$classname$" />

portion, or by allowing end users to customize the template that is used to generate the comments for the constructor.

0
Comment actions Permalink

Chris Thompson

ReSharper doesn't generate the comments itself. It looks like you have some 3rd-party plugin for VS or ReSharper (e.g. StyleCop) which adds the comments to make the code align with XML documentation requirements (when the comments are missing).

You managed to add the comment into the ctor template, but I'm afraid it wouldn't work with the rest (ctorp, ctorf, ctorfp) since they are added differently from the ctor, which is a template. These 3 are generated code and the are no templates to edit for them.

0

Please sign in to leave a comment.