JKToolKit.TemplatePropertyGenerator
0.0.1
See the version list below for details.
dotnet add package JKToolKit.TemplatePropertyGenerator --version 0.0.1
NuGet\Install-Package JKToolKit.TemplatePropertyGenerator -Version 0.0.1
<PackageReference Include="JKToolKit.TemplatePropertyGenerator" Version="0.0.1" />
paket add JKToolKit.TemplatePropertyGenerator --version 0.0.1
#r "nuget: JKToolKit.TemplatePropertyGenerator, 0.0.1"
// Install JKToolKit.TemplatePropertyGenerator as a Cake Addin #addin nuget:?package=JKToolKit.TemplatePropertyGenerator&version=0.0.1 // Install JKToolKit.TemplatePropertyGenerator as a Cake Tool #tool nuget:?package=JKToolKit.TemplatePropertyGenerator&version=0.0.1
<p align="center"> <a> <picture> <source media="(prefers-color-scheme: dark)" srcset="assets/logo/logo_small_128x128.png"> <img src="assetss/logo/logo_small_128x128.png" height="128"> </picture> <h1 align="center">TemplatePropertyGenerator</h1> </a> </p>
<p align="center"> <a href="https://www.nuget.org/packages/JKToolKit.TemplatePropertyGenerator/"><img src="https://img.shields.io/nuget/v/JKToolKit.TemplatePropertyGenerator" alt="NuGet"></a> <a href="https://www.nuget.org/packages/JKToolKit.TemplatePropertyGenerator/"><img src="https://img.shields.io/nuget/dt/JKToolKit.TemplatePropertyGenerator" alt="Nuget"></a> <a href="LICENSE"><img src="https://img.shields.io/github/license/JKamsker/JKToolKit.TemplatePropertyGenerator" alt="License"></a> <a href="https://github.com/JKamsker/JKToolKit.TemplatePropertyGenerator/pulls"><img src="https://img.shields.io/badge/PR-Welcome-blue" alt="PR"></a> <a href="https://github.com/JKamsker/JKToolKit.TemplatePropertyGenerator/actions/workflows/build-test.yml"><img src="https://img.shields.io/github/actions/workflow/status/JKamsker/JKToolKit.TemplatePropertyGenerator/build-test.yml?branch=master" alt="GitHub Workflow Status"></a> </p>
Overview
TemplatePropertyGenerator
is a C# source generator that creates strongly-typed template properties from annotated classes. This allows for easy and safe string formatting by generating classes with methods to format predefined templates.
Features
- Define template properties with format strings using attributes.
- Auto-generate classes with methods to format the strings.
- Supports FormattableString for more complex formatting needs.
How to Use
Install the NuGet package:
Ensure you have the NuGet package installed in your project. If not, you can install it via the NuGet Package Manager or the .NET CLI.
dotnet add package JKToolkit.TemplatePropertyGenerator
Define your templates:
Use the
TemplateProperty
attribute to define your template properties in a partial class. The attribute takes the name of the property and the format string as parameters.[TemplateProperty("Hello", "Hello {value}, {value}!")] [TemplateProperty("FooBar", "Foo {value}, Bar {value}")] public static partial class Consts { }
Use the generated code:
Once the generator runs, it will produce a class with properties and methods to format your strings. You can use these in your code as shown below:
private static void Main(string[] args) { Console.WriteLine(Consts.Hello.Template); // Output: Hello {value}, {value}! Console.WriteLine(Consts.Hello.Format("World")); // Output: Hello World, World! Console.WriteLine(Consts.FooBar.Format("Foo1", "Bar1")); // Output: Foo Foo1, Bar Bar1 }
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue to discuss any changes or improvements.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
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
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.9.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.