Raiqub.Generators.T4CodeWriter 1.0.64

Prefix Reserved
dotnet add package Raiqub.Generators.T4CodeWriter --version 1.0.64                
NuGet\Install-Package Raiqub.Generators.T4CodeWriter -Version 1.0.64                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Raiqub.Generators.T4CodeWriter" Version="1.0.64" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Raiqub.Generators.T4CodeWriter --version 1.0.64                
#r "nuget: Raiqub.Generators.T4CodeWriter, 1.0.64"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Raiqub.Generators.T4CodeWriter as a Cake Addin
#addin nuget:?package=Raiqub.Generators.T4CodeWriter&version=1.0.64

// Install Raiqub.Generators.T4CodeWriter as a Cake Tool
#tool nuget:?package=Raiqub.Generators.T4CodeWriter&version=1.0.64                

SourceGenerators

Build status OpenSSF Scorecard GitHub license

Provides utility functions and helpers to aid in writing source files for source generators based on T4 templates

🏃 Quickstart   |   📗 Guide   |   📦 NuGet

<hr />

Provides a high performance T4 base class on compiled library or source files package.

NuGet Packages

  • NuGet Raiqub.Generators.T4CodeWriter: provides a compiled library with a high performance T4 base class
  • NuGet Raiqub.Generators.T4CodeWriter.Sources: provides source files with a high performance T4 base class

Compatibility

Raiqub T4 Code Writer library requires .NET Standard 2.0 runtime to run, and the source files requires at least the .NET 6 SDK to run, but you can target earlier frameworks.

Quickstart

Add the package to your application using

dotnet add package Raiqub.Generators.T4CodeWriter.Sources

Adding the package the base class CodeWriterBase<T> will be available as a base class for T4 templates.

Guide

CodeWriterBase

To override the base class of a T4 template set the inherits attribute. For example:

<#@ template debug="false" linePragmas="false" hostspecific="false" language="C#" inherits="CodeWriterBase<MyModel>" #>

The constructor of CodeWriterBase class need to receive a StringBuilder instance, then T4 templates that inherits from CodeWriterBase need to define a constructor passing a StringBuilder instance to base class. For example:

<#+
    public MyWriter(StringBuilder builder) : base(builder)
    {
    }
#>

Additionally the method GetFileName must be implemented to define the name of file of the generated source. For example:

<#+
    public override string GetFileName() => $"{Model.Namespace ?? "_"}.{Model.Name}Extensions.g.cs";
#>

Optionally the method CanGenerateFor can be implemented to determine if source code should be generated according with the specified model state. For example:

<#+
    protected override bool CanGenerateFor(MyModel model) => model.Properties.Count > 0;
#>

CodeWriterDispatcher

The CodeWriterDispatcher is a dispatcher for code writers that generate compilation source. As it does not mutate any internal state is safe to define it as a static readonly field. Example:

private static readonly CodeWriterDispatcher<MyModel> s_dispatcher =
    new(
        sb => new MyWriter1(sb),
        sb => new MyWriter2(sb));

Then just call the GenerateSources method to generate source files using the SourceProductionContext. For example:

private static void Emit(
    Compilation compilation,
    SourceProductionContext context,
    ImmutableArray<MyModel> types)
{
    // ...
    s_dispatcher.GenerateSources(typesToGenerate, context);
}

Contributing

If something is not working for you or if you think that the source file should change, feel free to create an issue or Pull Request. I will be happy to discuss and potentially integrate your ideas!

License

See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.64 85 10/6/2024
1.0.52 108 8/25/2024
1.0.49 120 8/24/2024
1.0.10 107 3/24/2024
1.0.1 114 3/17/2024