diff --git a/docs/exclusion.md b/docs/exclusion.md
index 1a907531..5cfadf93 100644
--- a/docs/exclusion.md
+++ b/docs/exclusion.md
@@ -361,7 +361,7 @@ All binary files as defined by https://github.com/sindresorhus/binary-extensions
"zip",
"zipx"
```
-snippet source | anchor
+snippet source | anchor
@@ -378,5 +378,5 @@ Files that cannot contain comments are excluded.
"geojson",
"sln"
```
-snippet source | anchor
+snippet source | anchor
diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props
index eff6b0d7..88662a82 100644
--- a/src/Directory.Packages.props
+++ b/src/Directory.Packages.props
@@ -12,6 +12,7 @@
+
@@ -19,4 +20,4 @@
-
\ No newline at end of file
+
diff --git a/src/MarkdownSnippets/ContentValidation.cs b/src/MarkdownSnippets/ContentValidation.cs
index 2d077103..3718b34b 100644
--- a/src/MarkdownSnippets/ContentValidation.cs
+++ b/src/MarkdownSnippets/ContentValidation.cs
@@ -1,38 +1,37 @@
static class ContentValidation
{
- static Dictionary phrases = new()
- {
- {"a majority of ", "most"},
- {"a number of", "some or many"},
- {"at an early date", "soon"},
- {"at the conclusion of", "after or following"},
- {"at the present time", "now"},
- {"at this point in time", "now"},
- {"based on the fact that", "because or since"},
- {"despite the fact that", "although"},
- {"due to the fact that", "because"},
- {"during the course of", "during"},
- {"during the time that", "during or while"},
- {"have the capability to", "can"},
- {"in connection with", "about"},
- {"in order to", "to"},
- {"in regard to ", "regarding or about"},
- {"in the event of", "if"},
- {"in view of the fact that", "because"},
- {"it is often the case that", "often"},
- {"make reference to ", "refer to"},
- {"of the opinion that", "think that "},
- {"on a daily basis", "daily"},
- {"on the grounds that", "because"},
- {"prior to", "before"},
- {"so as to", "to"},
- {"subsequent to", "after"},
- {"take into consideration", "consider"},
- {"until such time as", "until"},
- {"a lot", "many"},
- {"sort of", "similar or approximately"},
- {"kind of", "similar or approximately "}
- };
+ static FrozenDictionary phrases = FrozenDictionary.Create([
+ new("a majority of ", "most"),
+ new("a number of", "some or many"),
+ new("at an early date", "soon"),
+ new("at the conclusion of", "after or following"),
+ new("at the present time", "now"),
+ new("at this point in time", "now"),
+ new("based on the fact that", "because or since"),
+ new("despite the fact that", "although"),
+ new("due to the fact that", "because"),
+ new("during the course of", "during"),
+ new("during the time that", "during or while"),
+ new("have the capability to", "can"),
+ new("in connection with", "about"),
+ new("in order to", "to"),
+ new("in regard to ", "regarding or about"),
+ new("in the event of", "if"),
+ new("in view of the fact that", "because"),
+ new("it is often the case that", "often"),
+ new("make reference to ", "refer to"),
+ new("of the opinion that", "think that "),
+ new("on a daily basis", "daily"),
+ new("on the grounds that", "because"),
+ new("prior to", "before"),
+ new("so as to", "to"),
+ new("subsequent to", "after"),
+ new("take into consideration", "consider"),
+ new("until such time as", "until"),
+ new("a lot", "many"),
+ new("sort of", "similar or approximately"),
+ new("kind of", "similar or approximately ")
+ ]);
static List invalidStrings;
@@ -135,4 +134,4 @@ static string Clean(string input)
span[index] = ' ';
});
}
-}
\ No newline at end of file
+}
diff --git a/src/MarkdownSnippets/Downloader/FileNameFromUrl.cs b/src/MarkdownSnippets/Downloader/FileNameFromUrl.cs
index 2f8d78a8..f4473ea7 100644
--- a/src/MarkdownSnippets/Downloader/FileNameFromUrl.cs
+++ b/src/MarkdownSnippets/Downloader/FileNameFromUrl.cs
@@ -1,6 +1,6 @@
static class FileNameFromUrl
{
- static HashSet invalid = [..Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars())];
+ static FrozenSet invalid = Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()).ToFrozenSet();
public static string ConvertToFileName(string url)
{
diff --git a/src/MarkdownSnippets/GlobalUsings.cs b/src/MarkdownSnippets/GlobalUsings.cs
index 42f8fa5e..85fa0932 100644
--- a/src/MarkdownSnippets/GlobalUsings.cs
+++ b/src/MarkdownSnippets/GlobalUsings.cs
@@ -1,4 +1,5 @@
-global using System.Diagnostics.CodeAnalysis;
+global using System.Collections.Frozen;
+global using System.Diagnostics.CodeAnalysis;
global using System.Net;
global using System.Net.Http;
global using System.Text.RegularExpressions;
diff --git a/src/MarkdownSnippets/MarkdownSnippets.csproj b/src/MarkdownSnippets/MarkdownSnippets.csproj
index b51bbf65..2828b7d3 100644
--- a/src/MarkdownSnippets/MarkdownSnippets.csproj
+++ b/src/MarkdownSnippets/MarkdownSnippets.csproj
@@ -7,7 +7,8 @@
+
-
\ No newline at end of file
+
diff --git a/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs b/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs
index de185e6d..14e6cf06 100644
--- a/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs
+++ b/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs
@@ -3,14 +3,15 @@
public static class SnippetFileExclusions
{
public static bool IsBinary(string extension) =>
- BinaryFileExtensions.Contains(extension);
+ binaryFileExtensionsFrozen.Contains(extension);
public static bool CanContainCommentsExtension(string extension) =>
- !NoAcceptCommentsExtensions.Contains(extension);
+ !noAcceptCommentsExtensionsFrozen.Contains(extension);
- public static HashSet NoAcceptCommentsExtensions { get; set; } =
- new(StringComparer.OrdinalIgnoreCase)
- {
+ static FrozenSet noAcceptCommentsExtensionsFrozen = FrozenSet.Create(
+ StringComparer.OrdinalIgnoreCase,
+ source:
+ [
//files that dont accept comments hence cant contain snippets
#region NoAcceptCommentsExtensions
@@ -22,11 +23,34 @@ public static bool CanContainCommentsExtension(string extension) =>
"sln"
#endregion
- };
+ ]);
+
+ public static void AddNoAcceptCommentsExtensions(params string[] extensions)
+ {
+ var set = new HashSet(noAcceptCommentsExtensionsFrozen, StringComparer.OrdinalIgnoreCase);
+ foreach (var extension in extensions)
+ {
+ set.Add(extension);
+ }
- public static HashSet BinaryFileExtensions { get; set; } =
- new(StringComparer.OrdinalIgnoreCase)
+ noAcceptCommentsExtensionsFrozen = set.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
+ }
+
+ public static void RemoveNoAcceptCommentsExtensions(params string[] extensions)
+ {
+ var set = new HashSet(noAcceptCommentsExtensionsFrozen, StringComparer.OrdinalIgnoreCase);
+ foreach (var extension in extensions)
{
+ set.Remove(extension);
+ }
+
+ noAcceptCommentsExtensionsFrozen = set.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
+ }
+
+ static FrozenSet binaryFileExtensionsFrozen = FrozenSet.Create(
+ StringComparer.OrdinalIgnoreCase,
+ source:
+ [
#region BinaryFileExtensions
"user",
@@ -297,5 +321,27 @@ public static bool CanContainCommentsExtension(string extension) =>
"zipx"
#endregion
- };
-}
\ No newline at end of file
+ ]);
+
+ public static void AddBinaryFileExtensions(params string[] extensions)
+ {
+ var set = new HashSet(binaryFileExtensionsFrozen, StringComparer.OrdinalIgnoreCase);
+ foreach (var extension in extensions)
+ {
+ set.Add(extension);
+ }
+
+ binaryFileExtensionsFrozen = set.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
+ }
+
+ public static void RemoveBinaryFileExtensions(params string[] extensions)
+ {
+ var set = new HashSet(binaryFileExtensionsFrozen, StringComparer.OrdinalIgnoreCase);
+ foreach (var extension in extensions)
+ {
+ set.Remove(extension);
+ }
+
+ binaryFileExtensionsFrozen = set.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
+ }
+}
diff --git a/src/MarkdownSnippets/Reading/FileSnippetExtractor.cs b/src/MarkdownSnippets/Reading/FileSnippetExtractor.cs
index d46ae9a5..b80c8c7c 100644
--- a/src/MarkdownSnippets/Reading/FileSnippetExtractor.cs
+++ b/src/MarkdownSnippets/Reading/FileSnippetExtractor.cs
@@ -18,7 +18,7 @@ public static Task AppendUrlAsSnippet(this ICollection snippets, string
/// Each url will be accessible using the file name as a key. Any snippets within the files will be extracted and accessible as individual keyed snippets.
///
public static Task AppendUrlsAsSnippets(this ICollection snippets, params string[] urls) =>
- AppendUrlsAsSnippets(snippets, (IEnumerable) urls);
+ snippets.AppendUrlsAsSnippets((IEnumerable) urls);
///
/// Each url will be accessible using the file name as a key. Any snippets within the files will be extracted and accessible as individual keyed snippets.
@@ -27,7 +27,7 @@ public static async Task AppendUrlsAsSnippets(this ICollection snippets
{
foreach (var url in urls)
{
- await AppendUrlAsSnippet(snippets, url);
+ await snippets.AppendUrlAsSnippet(url);
}
}
@@ -63,7 +63,7 @@ public static void AppendFilesAsSnippets(this ICollection snippets, par
{
foreach (var filePath in filePaths)
{
- AppendFileAsSnippet(snippets, filePath);
+ snippets.AppendFileAsSnippet(filePath);
}
}
@@ -211,4 +211,4 @@ static Snippet BuildSnippet(string path, LoopStack loopStack, string language, i
expressiveCode: loopState.ExpressiveCode
);
}
-}
\ No newline at end of file
+}