VS2026扩展插件Visual Commander

摘要:

为解决代码注释中添加修改日期时间的需求,发现Visual Commander插件可为VS2026扩展功能。通过编写简单C#代码实现自动插入当前时间功能,关键是将Selection转换为TextSelection类型。该插件官网提供51个示例(部分VB代码),可借助AI转换为C#代码满足多种开发需求。

在编写代码的时候,希望在方法的注释中添加一个修改日期和时间。

使用Code Snippet 发现不行。

找插件,也没找到。

不过找到了这个插件,Visual Commander可以为VS2026简单地扩展一下功能。

官网:https://vlasovstudio.com/visual-commander/commands.html

一段简单的代码就可以完成需要的功能

csharp 复制代码
using System;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;

public class InsertDateTime : VisualCommanderExt.ICommand
{
	public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
	{
		// 确保有活动文档
		if (DTE.ActiveDocument == null) return;
		
		// 获取当前日期时间
		var date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
		
		// 关键:将 Selection 转换为 TextSelection 类型
		var selection = DTE.ActiveDocument.Selection as TextSelection;
		if (selection != null)
		{
			selection.Text = date;
		}
	}
}

官方示例写了51个,覆盖了大部分需求,但有部分是VB代码。这些代码使用AI可以很容易地转成C#代码。

相关推荐
Geek-Chow13 分钟前
微服务认证与授权:01 — 概念
java·前端·数据库
KobeSacre18 分钟前
DelayQueue 源码
java·开发语言
Wang's Blog26 分钟前
JavaWeb快速入门: Filter与Listener核心详解
java·filter·listener
han_hanker31 分钟前
重新认识枚举enum
开发语言
zfoo-framework35 分钟前
mongodb性能调优 1.从慢查询分析索引 2.掌握索引最左匹配原则!!!
java
AIGS0011 小时前
企业AI落地:从RAG到AgentRAG的技术跃迁
java·人工智能·人工智能ai大模型应用
鹏易灵1 小时前
C++——8.移动语义初探(移动构造、移动赋值)
开发语言·c++·php
2601_962341301 小时前
计算机毕业设计之jsp考研在线复习平台
java·大数据·开发语言·hadoop·python·考研·课程设计
凯瑟琳.奥古斯特1 小时前
力扣1008:前序重建BST
开发语言·c++·算法·leetcode·职场和发展