| 123456789101112131415161718192021222324252627282930313233343536373839 |
- using System.Threading.Tasks;
- using Community.VisualStudio.Toolkit;
- namespace VberAdmin.Helpers;
- public static class Helper
- {
- public static async Task<bool> CheckFileAsync()
- {
- var docView = await VS.Documents.GetActiveDocumentViewAsync();
- if (docView == null)
- {
- await VS.MessageBox.ShowWarningAsync("未发现当前需操作的对象");
- return false;
- }
- string fileName = docView.FilePath ?? "";
- if (!fileName.EndsWith(".cs"))
- {
- await VS.MessageBox.ShowWarningAsync("操作文件错误:", " 请在后缀为 [.cs]的文件中使用插件!");
- return false;
- }
- PhysicalFile item = await PhysicalFile.FromFileAsync(fileName);
- Project project = item?.ContainingProject;
- if (project == null)
- {
- await VS.MessageBox.ShowWarningAsync("未发现当前需操作项目。");
- return false;
- }
- if (!project.Name.EndsWith(".Core"))
- {
- await VS.MessageBox.ShowWarningAsync("操作项目错误:", "请在后缀为 [.Core] 项目中使用插件。");
- return false;
- }
- return true;
- }
- }
|