Generates strongly typed access methods for none item files.
$ dotnet add package Raffinert.NoneItemAccessGeneratorA refined version of the original EmbeddedResourceAccessGenerator by ChristophHornung adapted for None items.
Important: The original EmbeddedResourceAccessGenerator is incompatible with this generator and must be removed before adding this generator.
The Raffinert.NoneItemAccessGenerator is a code generator to allow easy access to all none item files with CopyToOutputDirectory attribute specified as Always or PreserveNewest.
Get the nuget package here.
After referencing the Raffinert.NoneItemAccessGenerator nuget the code generation will
automatically create a class Nones in the root namespace of the project.
Together with the generated None enumeration there are several options to access
none item files:
E.g. for a Test.txt none item in the TestAsset folder:
None enum:// Via the generated extension methods on the enum
using Stream s = None.TestAsset_Test_txt.GetStream();
using StreamReader sr = None.TestAsset_Test_txt.GetReader();
string text = None.TestAsset_Test_txt.ReadAllText();
string textAsync = await None.TestAsset_Test_txt.ReadAllTextAsync(CancellationToken.None);
byte[] bytes = None.TestAsset_Test_txt.ReadAllBytes();
byte[] bytesAsync = await None.TestAsset_Test_txt.ReadAllBytesAsync(CancellationToken.None);
None[FolderName] enum:// Via the generated extension methods on the enum
using Stream s = None_TestAsset.Test_txt.GetStream();
using StreamReader sr = None_TestAsset.Test_txt.GetReader();
string text = None_TestAsset.Test_txt.ReadAllText();
string textAsync = await None_TestAsset.Test_txt.ReadAllTextAsync(CancellationToken.None);
byte[] bytes = None_TestAsset.Test_txt.ReadAllBytes();
byte[] bytesAsync = await None_TestAsset.Test_txt.ReadAllBytesAsync(CancellationToken.None);
GetMatches for Pattern Matchingvar matches = Nones.GetMatches("**/*");
foreach (var none in matches)
{
Console.WriteLine(none);
}
[Theory]
[Nones.FromPattern("**/*test.txt")]
public void PrintNonePath(None file)
{
testOutputHelper.WriteLine(file.GetNoneFilePath());
}