Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 11, 2025
1 parent d2964dd commit 1b17763
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
23 changes: 19 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ FileExtensions.AddTextExtension(".ext1");
True(FileExtensions.IsTextExtension(".ext1"));
True(FileExtensions.IsTextFile("file.ext1"));
```
<sup><a href='/src/Tests/ExtensionsTests.cs#L36-L42' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddTextExtension' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/ExtensionsTests.cs#L51-L57' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddTextExtension' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -268,7 +268,7 @@ True(FileExtensions.IsTextExtension(".ext1"));
FileExtensions.RemoveTextExtension(".ext1");
False(FileExtensions.IsTextExtension(".ext1"));
```
<sup><a href='/src/Tests/ExtensionsTests.cs#L52-L59' title='Snippet source file'>snippet source</a> | <a href='#snippet-RemoveTextExtension' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/ExtensionsTests.cs#L67-L74' title='Snippet source file'>snippet source</a> | <a href='#snippet-RemoveTextExtension' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -278,11 +278,26 @@ False(FileExtensions.IsTextExtension(".ext1"));

At app startup add a convention using `FileExtensions.AddTextFileConvention`:

snippet: AddTextFileConvention
<!-- snippet: AddTextFileConvention -->
<a id='snippet-AddTextFileConvention'></a>
```cs
[ModuleInitializer]
public static void AddTextFileConvention() =>
// Treat files ending with .txtViaConvention as text files
FileExtensions.AddTextFileConvention(path => path.EndsWith(".txtViaConvention"));
```
<sup><a href='/src/Tests/ExtensionsTests.cs#L24-L30' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddTextFileConvention' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Then any call to `FileExtensions.IsTextFile` will, in addition to checking the known text extensions, also check if any of the added text contentions return true.

snippet: TextViaConvention
<!-- snippet: TextViaConvention -->
<a id='snippet-TextViaConvention'></a>
```cs
True(FileExtensions.IsTextFile("c:/path/file.txtViaConvention"));
```
<sup><a href='/src/Tests/ExtensionsTests.cs#L17-L21' title='Snippet source file'>snippet source</a> | <a href='#snippet-TextViaConvention' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## Icon
Expand Down
1 change: 1 addition & 0 deletions src/EmptyFiles.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Packages.props = Directory.Packages.props
..\readme.md = ..\readme.md
global.json = global.json
mdsnippets.json = mdsnippets.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmptyFiles", "EmptyFiles\EmptyFiles.csproj", "{A017D3FD-7DA5-4DF4-A169-72DE4AF76048}"
Expand Down
2 changes: 1 addition & 1 deletion src/mdsnippets.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/SimonCropp/MarkdownSnippets/master/schema.json",
"TocExcludes": [ "NuGet package", "Release Notes", "Icon" ],
"MaxWidth": 80,
"MaxWidth": 100,
"Convention": "InPlaceOverwrite"
}

0 comments on commit 1b17763

Please sign in to comment.