VS2019 利用 Macro 函数注释 添加 姓名 和 日期

1.添加 Macros for Visual Studio 扩展

2. 添加 Macro 脚本

Method Note 中的 代码如下(一键下载文章中使用的Macro文件): 

var date = new Date();

var year = date.getYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();

month = month < 10 ? ("0" + month) : ("" + month);
day = day < 10 ? ("0" + day) : ("" + day);
hours = hours < 10 ? ("0" + hours) : ("" + hours);
minutes = minutes < 10 ? ("0" + minutes) : ("" + minutes);

var doc = dte.ActiveDocument;

doc.Selection.Text = "///";
doc.Selection.LineDown();

doc.Selection.EndOfLine();
doc.Selection.NewLine();
doc.Selection.Text = "<remark>";
doc.Selection.NewLine();
doc.Selection.LineUp();
doc.Selection.EndOfLine();
doc.Selection.NewLine();
doc.Selection.Text = "<para/>Author   :  AnDequan";
doc.Selection.NewLine();
doc.Selection.Text = "<para/>Date     :  " + year + "-" + month + "-" + day + " " + hours + ":" + minutes;

3.添加 快捷键 ,本人用的 Ctrl M,1

4.效果演示:

在 Class 或者 函数 上 使用快捷键 Ctrl M,1 即可

同理做了一个单行注释如下图:

# 附录:
MethodNote.js
 

var date = new Date();

var year = date.getYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();

if (month == 1) month = 13;
if (month == 2) month = 14;
var week = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7 + 1;
week = parseInt(week);
var xingqi = "";
if (week == 1) { xingqi = "星期日"; }
else if (week == 2) { xingqi = "星期一"; }
else if (week == 3) { xingqi = "星期二"; }
else if (week == 4) { xingqi = "星期三"; }
else if (week == 5) { xingqi = "星期四"; }
else if (week == 6) { xingqi = "星期五"; }
else if (week == 7) { xingqi = "星期六"; }


month = month < 10 ? ("0" + month) : ("" + month);
day = day < 10 ? ("0" + day) : ("" + day);
hours = hours < 10 ? ("0" + hours) : ("" + hours);
minutes = minutes < 10 ? ("0" + minutes) : ("" + minutes);

var time = year + "-" + month + "-" + day + " " + hours + ":" + minutes;
var justDay = year + "-" + month + "-" + day;
var doc = dte.ActiveDocument;

doc.Selection.Text = "///";
doc.Selection.LineDown();

doc.Selection.EndOfLine();
doc.Selection.NewLine();
doc.Selection.Text = "<remark>";
doc.Selection.NewLine();
doc.Selection.LineUp();
doc.Selection.EndOfLine();
doc.Selection.NewLine();
doc.Selection.Text = "<para/>Author   :  An";
doc.Selection.NewLine();
doc.Selection.Text = "<para/>Date     :  " + time + " " + xingqi;
doc.Selection.LineUp();
doc.Selection.LineUp();
doc.Selection.LineUp();
doc.Selection.LineUp();


SingleLineNote.js
 

var date = new Date();

var year = date.getYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();

if (month == 1) month = 13;
if (month == 2) month = 14;
var week = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7 + 1;
week = parseInt(week);
var xingqi = "";
if (week == 1) { xingqi = "星期日"; }
else if (week == 2) { xingqi = "星期一"; }
else if (week == 3) { xingqi = "星期二"; }
else if (week == 4) { xingqi = "星期三"; }
else if (week == 5) { xingqi = "星期四"; }
else if (week == 6) { xingqi = "星期五"; }
else if (week == 7) { xingqi = "星期六"; }


month = month < 10 ? ("0" + month) : ("" + month);
day = day < 10 ? ("0" + day) : ("" + day);
hours = hours < 10 ? ("0" + hours) : ("" + hours);
minutes = minutes < 10 ? ("0" + minutes) : ("" + minutes);

var time = year + "-" + month + "-" + day + " " + hours + ":" + minutes;
var justDay = year + "-" + month + "-" + day;

var doc = dte.ActiveDocument;
doc.Selection.Text = "// [  ] An " + time + " " + xingqi + "";
doc.Selection.CharLeft(false, 24);
doc.Selection.CharLeft();
doc.Selection.Text = "";
doc.Selection.CharLeft();
doc.Selection.Text = "";

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安得权

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值