Raiqub.Generators.T4CodeWriter.Sources 1.0.10

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Raiqub.Generators.T4CodeWriter.Sources --version 1.0.10
NuGet\Install-Package Raiqub.Generators.T4CodeWriter.Sources -Version 1.0.10
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.Sources" Version="1.0.10">
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Raiqub.Generators.T4CodeWriter.Sources --version 1.0.10
#r "nuget: Raiqub.Generators.T4CodeWriter.Sources, 1.0.10"
#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.Sources as a Cake Addin
#addin nuget:?package=Raiqub.Generators.T4CodeWriter.Sources&version=1.0.10

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


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


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.


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.



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;


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 =
        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);


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!


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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has 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.

Version Downloads Last updated
1.0.10 129 3/24/2024
1.0.1 102 3/17/2024