DragoAnt.Extensions.T4
1.0.1
dotnet add package DragoAnt.Extensions.T4 --version 1.0.1
NuGet\Install-Package DragoAnt.Extensions.T4 -Version 1.0.1
<PackageReference Include="DragoAnt.Extensions.T4" Version="1.0.1" />
<PackageVersion Include="DragoAnt.Extensions.T4" Version="1.0.1" />
<PackageReference Include="DragoAnt.Extensions.T4" />
paket add DragoAnt.Extensions.T4 --version 1.0.1
#r "nuget: DragoAnt.Extensions.T4, 1.0.1"
#:package DragoAnt.Extensions.T4@1.0.1
#addin nuget:?package=DragoAnt.Extensions.T4&version=1.0.1
#tool nuget:?package=DragoAnt.Extensions.T4&version=1.0.1
Extensions.T4
Overview
Extensions.T4 is a library designed to enhance the capabilities of T4 (Text Template Transformation Toolkit) templates. It provides utilities and extensions that simplify the process of generating code using T4 templates.
Purpose
The main purpose of this package is to facilitate the generation of data-driven code using T4 templates. It allows developers to define templates that can dynamically generate code based on input data, making it easier to maintain and scale codebases.
Features
- Data-Driven Code Generation: Use input data to drive the generation of code, reducing manual coding and potential errors.
- Customizable Templates: Create templates that can be reused across different projects or modules.
- Integration with Existing Projects: Easily integrate T4 templates into existing projects to automate repetitive coding tasks.
Example Usage
Below is an example of how to use a T4 template with the Extensions.T4 package. This example demonstrates generating a static class with a property that returns an array of integers.
T4 Template: TestTemplate.tt
<#@ template language="C#" linePragmas="false" inherits="BaseTransformation<TemplateTestData>" visibility="internal" #>
<#@ import namespace="DragoAnt.Extensions.T4" #>
namespace <#= Data.Namespace #>;
internal static class TestClass
{
public static int[] Property => [<#= string.Join(", ", Data.Numbers) #>];
}
Explanation
- Template Inheritance: The template inherits from
BaseTransformation<TemplateTestData>, allowing it to access the data modelTemplateTestData. - Namespace Generation: The namespace is dynamically generated using
Data.Namespace. - Property Generation: The
Propertyis an array of integers, generated fromData.Numbers.
Project Properties for .tt File
To ensure the .tt file works correctly, make sure the following properties are set in your project file (.csproj):
- Generator: Set to
TextTemplatingFilePreprocessor. - LastGenOutput: Specifies the output file name, e.g.,
TestTemplate.cs.
Example of TemplateTestData
Here's an example of what the TemplateTestData class might look like:
public class TemplateTestData
{
public string Namespace { get; set; }
public List<int> Numbers { get; set; }
}
How to Use TestTemplate
Here's a step-by-step example similar to the one in TemplateTests.cs:
Prepare Data: Create an instance of
TemplateTestDatawith the desired namespace and numbers.var data = new TemplateTestData { Namespace = "MyNamespace", Numbers = new List<int> { 1, 2, 3 } };Run the Template: Use the T4 template engine to process
TestTemplate.ttwith your data.var template = new TestTemplate { Data = data }; var result = template.TransformText();Integrate Generated Code: The generated code will be available in your project, ready for use.
Getting Started
To start using Extensions.T4, include it in your project and create T4 templates as shown in the example. Customize the templates to fit your specific needs and data structures.
License
This project is licensed under the terms of the MIT license. See the LICENSE file for details.
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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 (2)
Showing the top 2 NuGet packages that depend on DragoAnt.Extensions.T4:
| Package | Downloads |
|---|---|
|
DragoAnt.Extensions.DependencyInjection
DragoAnt.Extensions.DependencyInjection |
|
|
DragoAnt.Extensions.DependencyInjection.Referenced
DragoAnt.Extensions.DependencyInjection.Referenced |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 5,151 | 12/23/2024 |