Raffinert.NoneItemAccessGenerator
1.0.12
dotnet add package Raffinert.NoneItemAccessGenerator --version 1.0.12
NuGet\Install-Package Raffinert.NoneItemAccessGenerator -Version 1.0.12
<PackageReference Include="Raffinert.NoneItemAccessGenerator" Version="1.0.12"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Raffinert.NoneItemAccessGenerator" Version="1.0.12" />
<PackageReference Include="Raffinert.NoneItemAccessGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Raffinert.NoneItemAccessGenerator --version 1.0.12
#r "nuget: Raffinert.NoneItemAccessGenerator, 1.0.12"
#:package Raffinert.NoneItemAccessGenerator@1.0.12
#addin nuget:?package=Raffinert.NoneItemAccessGenerator&version=1.0.12
#tool nuget:?package=Raffinert.NoneItemAccessGenerator&version=1.0.12
A 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.
NoneItemAccessGenerator
The Raffinert.NoneItemAccessGenerator is a code generator to allow easy access to all none item files with CopyToOutputDirectory attribute specified as Always or PreserveNewest.
Usage
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:
- Via enum access through the
Noneenum:
// 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);
- Via enum access through the
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);
Using GetMatches for Pattern Matching
var matches = Nones.GetMatches("**/*");
foreach (var none in matches)
{
Console.WriteLine(none);
}
xUnit integration
[Theory]
[Nones.FromPattern("**/*test.txt")]
public void PrintNonePath(None file)
{
testOutputHelper.WriteLine(file.GetNoneFilePath());
}
See also:
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v 1.0.12 - Add missing xml comment to FromPatternAttribute.GetData method (issue #15).
v 1.0.11 - Add missing usings to the generated code.
v 1.0.10 - Add Nones.FromPattern xUnit attribute for use with the Theory attribute.
v 1.0.9 - Remove dependency on DotNet.Glob.
v 1.0.8 - Add Nones.GetMatches method.
v 1.0.7 - Downgrade version of Microsoft.CodeAnalysis.CSharp to be compatible with entityframework design tools.
v 1.0.6 - Add GetFileInfo extension.
v 1.0.5 - Fix missing using System.Threading directive.
v 1.0.4 - Fix missing using System.Threading.Tasks directive.
v 1.0.3 - Separate readmes between the projects and update them.
v 1.0.2 - Added ReadAllBytes and ReadAllBytesAsync methods
v.1.0.1 - Fix the msbuild condition
v.1.0.0 - Initial release.