From 753a293343e5cec68d94dfd2e2b1d73fb09efc06 Mon Sep 17 00:00:00 2001 From: Traian Coza Date: Thu, 9 May 2024 21:15:05 -0400 Subject: [PATCH] Added .vb file support --- NamespaceAdjuster/NamespaceAdjuster.csproj | 1 + .../FileNamespaceUpdaterProvider.cs | 1 + .../VbNamespaceUpdaterService.cs | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 NamespaceAdjuster/NamespaceUpdater/VbNamespaceUpdaterService.cs diff --git a/NamespaceAdjuster/NamespaceAdjuster.csproj b/NamespaceAdjuster/NamespaceAdjuster.csproj index d0e364c..12c2291 100644 --- a/NamespaceAdjuster/NamespaceAdjuster.csproj +++ b/NamespaceAdjuster/NamespaceAdjuster.csproj @@ -52,6 +52,7 @@ + diff --git a/NamespaceAdjuster/NamespaceUpdater/FileNamespaceUpdaterProvider.cs b/NamespaceAdjuster/NamespaceUpdater/FileNamespaceUpdaterProvider.cs index 98223fe..6692d88 100644 --- a/NamespaceAdjuster/NamespaceUpdater/FileNamespaceUpdaterProvider.cs +++ b/NamespaceAdjuster/NamespaceUpdater/FileNamespaceUpdaterProvider.cs @@ -11,6 +11,7 @@ internal class FileNamespaceUpdaterProvider public FileNamespaceUpdaterProvider() { updaterServices.Add(new CsNamespaceUpdaterService()); + updaterServices.Add(new VbNamespaceUpdaterService()); } public IFileNamespaceUpdater GetUpdater(string filePath) diff --git a/NamespaceAdjuster/NamespaceUpdater/VbNamespaceUpdaterService.cs b/NamespaceAdjuster/NamespaceUpdater/VbNamespaceUpdaterService.cs new file mode 100644 index 0000000..194f495 --- /dev/null +++ b/NamespaceAdjuster/NamespaceUpdater/VbNamespaceUpdaterService.cs @@ -0,0 +1,21 @@ +using System.Text.RegularExpressions; + +namespace NamespaceUpdater +{ + internal class VbNamespaceUpdaterService : LogicFileNamespaceUpdaterService + { + protected override string SupportedFileExtension => ".vb"; + + protected override string NamespaceStartLimiter => string.Empty; + + protected override string NamespaceEndLimiter => "End Namespace"; + + protected override Match FindNamespaceMatch(string fileContent) => + Regex.Match(fileContent, @"[\r\n|\r|\n]?Namespace\s(.+)"); + + protected override MatchCollection FindUsingMatches(string fileContent) => + Regex.Matches(fileContent, @"\n?Imports\s(.+)"); + + protected override string BuildNamespaceLine(string desiredNamespace) => "Namespace " + desiredNamespace; + } +}