Helper.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Threading.Tasks;
  2. using Community.VisualStudio.Toolkit;
  3. namespace VberAdmin.Helpers;
  4. public static class Helper
  5. {
  6. public static async Task<bool> CheckFileAsync()
  7. {
  8. var docView = await VS.Documents.GetActiveDocumentViewAsync();
  9. if (docView == null)
  10. {
  11. await VS.MessageBox.ShowWarningAsync("未发现当前需操作的对象");
  12. return false;
  13. }
  14. string fileName = docView.FilePath ?? "";
  15. if (!fileName.EndsWith(".cs"))
  16. {
  17. await VS.MessageBox.ShowWarningAsync("操作文件错误:", " 请在后缀为 [.cs]的文件中使用插件!");
  18. return false;
  19. }
  20. PhysicalFile item = await PhysicalFile.FromFileAsync(fileName);
  21. Project project = item?.ContainingProject;
  22. if (project == null)
  23. {
  24. await VS.MessageBox.ShowWarningAsync("未发现当前需操作项目。");
  25. return false;
  26. }
  27. if (!project.Name.EndsWith(".Core"))
  28. {
  29. await VS.MessageBox.ShowWarningAsync("操作项目错误:", "请在后缀为 [.Core] 项目中使用插件。");
  30. return false;
  31. }
  32. return true;
  33. }
  34. }