-1

I would like to change default template for adding a new C# class in Visual Studio 2019.

So when you right click C# project and then go Add new item -> Class (or Shift + Alft + C keyboard shortcut) I get a new file with class. I'd like to add public access modifier by default for every class created. To do that I edited this file: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs

I successfully and file now looks like this:

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
    public class $safeitemrootname$
    {
      // initial cursor position should be here
    }
}

In addition I'd like to set default cursor (caret) position to the position between class' curly brackets (where I put comment) so that I can immediately start typing the code (without having to lift my hands off the keyboard just to grab the mouse to position the caret there). Is there a way to do this in Visual Studio? I know there is solution with ReSharper but I don't use it.

mlst
  • 2,688
  • 7
  • 27
  • 57

1 Answers1

1

Based on my research, I find that it is hard for us to set the cursor position by changing the class file directly.

However, If you are interested in the visual-studio extension, you can look at the following link to set the cursor position.

Setting cursor position with Visual Studio Extension

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27