zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Visual Studio 2019 修改注释快捷键和添加自定义头部注释

2023-04-18 14:08:06 时间

1、修改注释快捷键

将"编辑.切换行注释"的快捷键修改为"Alt+/",点击"分配",“确定”,即可完成 Visual Studio 2019 注释快捷键的修改(修改为"Alt+/"),返回编辑器书写代码,对指定行添加注释和取消注释已成功。

2、添加自定义 C# 代码头部注释

打开 Visual Studio 2019 安装路径:E:Program Files (x86)Microsoft Visual Studio2019CommunityCommon7IDEItemTemplatesCSharpCode2052,修改如下文件: (1)E:Program Files (x86)Microsoft Visual Studio2019CommunityCommon7IDEItemTemplatesCSharpCode2052ClassClass.cs

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$
{
	/// <summary>
    ///********************************************
    /// ClassName    :  $safeitemrootname$
    /// Author       :  WeiXiaolei
    /// CreateTime   :  $time$ 
    /// Description  :  
    ///********************************************/
    /// </summary>
    class $safeitemrootname$
    {
    }
}

(2)E:Program Files (x86)Microsoft Visual Studio2019CommunityCommon7IDEItemTemplatesCSharpCode2052InterfaceInterface.cs

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$
{
	/// <summary>
    ///********************************************
    /// InterfaceName :  $safeitemrootname$
    /// Author        :  WeiXiaolei
    /// CreateTime    :  $time$ 
    /// Description   :  
    ///********************************************/
    /// </summary>
    interface $safeitemrootname$
    {
    }
}

(3)E:Program Files (x86)Microsoft Visual Studio2019CommunityCommon7IDEItemTemplatesCSharpCode2052WebClassClass.cs

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Web;

namespace $rootnamespace$
{
	/// <summary>
    ///********************************************
    /// ClassName    :  $safeitemrootname$
    /// Author       :  WeiXiaolei
    /// CreateTime   :  $time$ 
    /// Description  :  
    ///********************************************/
    /// </summary>
	public class $safeitemrootname$
	{
	}
}

修改完成,在 Visual Studio 2019 编辑器中添加新类 HelloWorld.cs,出现自定义头部注释如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    /// <summary>
    ///********************************************
    /// ClassName    :  HelloWorld
    /// Author       :  WeiXiaolei
    /// CreateTime   :  2021/11/4 12:15:09 
    /// Description  :  
    ///********************************************/
    /// </summary>
    class HelloWorld
    {
    }
}

添加新接口 IHello.cs,出现自定义头部注释如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    /// <summary>
    ///********************************************
    /// InterfaceName :  IHello
    /// Author        :  WeiXiaolei
    /// CreateTime    :  2021/11/4 12:15:40 
    /// Description   :  
    ///********************************************/
    /// </summary>
    interface IHello
    {
    }
}

Visual Studio 2019 C# 代码添加头部注释成功。