beswarm.ResxSourceGenerator
1.0.0
Prefix Reserved
See the version list below for details.
dotnet add package beswarm.ResxSourceGenerator --version 1.0.0
NuGet\Install-Package beswarm.ResxSourceGenerator -Version 1.0.0
<PackageReference Include="beswarm.ResxSourceGenerator" Version="1.0.0" />
paket add beswarm.ResxSourceGenerator --version 1.0.0
#r "nuget: beswarm.ResxSourceGenerator, 1.0.0"
// Install beswarm.ResxSourceGenerator as a Cake Addin #addin nuget:?package=beswarm.ResxSourceGenerator&version=1.0.0 // Install beswarm.ResxSourceGenerator as a Cake Tool #tool nuget:?package=beswarm.ResxSourceGenerator&version=1.0.0
NAME
Generate strong typed variables from resources item
The major problem with resources is that they are accessed by item name via a string. This is not type safe and can lead to errors such as:
Input errors.
The impossibility of having intellisense.
This package generate strong typed vars that provide secure access to resources.
Classical resx access:
ressourcemanager.GetString("Item");
with this package:
ResClass.Item();
Usage
Add the package to your project.
<PropertyGroup>
...
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
...
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BeSwarm.ResxSourceGenerator" Version="1.0.0" />
<AdditionalFiles Include="**/*.resx" />
</ItemGroup>
Code Example
When ResSourceGenerator is executed, code is generated.
Sample: Project have resources named App.resx and App.fr.resx
App have one item named Item1 with value "Text" and one item Item2 with value "Confirm delete {0} ?"
Two stong typed getters are generated:
namespace LibPages.Resources;
public partial class AppRes
{ ....
public global::System.Globalization.CultureInfo? Culture { get; set; }
public string? Item1()=>GetString("Item1","<?Item1?>",null);
public string? Item2(object? arg0)=>GetString("Item2","<?Item2?>",arg0);
}
For all strong typed getters, the first parameter is the name of the resource item.
The second parameter is the default value if the item is not found. This is useful for detect missing translated resources.
The third parameter is the arguments of the item.
Usage: With Dependency injection:
services.AddScoped<AppRes>();
in razor page
[Inject] AppRes _appRes{ get; set; } = default!;
or with a clasic new
AppRes _appRes=new();
access to resources items
_appRes.Item1(); // return "Text"
_appRes.Item2("test"); //return Confirm delete test ?
Nota: By default the culture is the default context culture. It is possible to change the culture with the property Culture.
_appRes.Culture=CultureInfo.GetCultureInfo("fr");
Company
Be Swarm https://beswarm.fr/developpeur_en/
Author
thierry roustan
License
MIT
Versions
- 1.0.0
- Initial release
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.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.