CommonUtils.Framework/Editor/EditorUtil.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Windows.Forms;
namespace CommonUtils
{
public static class EditorUtil
{
private static IServiceProvider _serviceProvider;
//Use EditorUtil.SetServiceProvider(this); in Package.cs
public static void SetServiceProvider(IServiceProvider serviceProvider)
=> _serviceProvider = serviceProvider;
//封装在Microsoft.VisualStudio.Interop.dll里的提示框
//标题:Microsoft Visual Studio
public static void ShowMessage(object value, params object[] args)
{
var message = value.ToString();
if (args.Length > 0)
message = string.Format(message, args);
VsShellUtilities.ShowMessageBox(_serviceProvider, message, "IDE提示", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}
[Obsolete("log不出来")]
public static void LogMessage(string message)
=> VsShellUtilities.LogMessage("", message, __ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION);
public static DTE GetIde()
{
ThreadHelper.ThrowIfNotOnUIThread();
return Package.GetGlobalService(typeof(DTE)) as DTE;
}
public static Documents GetDocuments()
=> GetIde().Documents;
public static Document GetActiveDocument()
=> GetIde().ActiveDocument;
//TextDocument 包含了 选中文本 光标位置
public static TextDocument GetTextDocument()
=> GetActiveDocument()?.Object() as TextDocument;
public static string GetText(this Document doc)
=> FileUtil.GetText(doc?.FullName);
public static string GetFullName(this TextDocument doc)
=> doc?.Parent?.FullName;
public static string GetText(this TextDocument doc)
=> FileUtil.GetText(doc.GetFullName());
public static string GetText()
=> GetActiveDocument()?.GetText();
public static void SaveText(string text)
=> FileUtil.Save(GetActiveDocument().FullName, text);
后面还有 42 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。