CSharpAuthor 2.0.0-preview1002

This is a prerelease version of CSharpAuthor.
There is a newer version of this package available.
See the version list below for details.
dotnet add package CSharpAuthor --version 2.0.0-preview1002
                    
NuGet\Install-Package CSharpAuthor -Version 2.0.0-preview1002
                    
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="CSharpAuthor" Version="2.0.0-preview1002" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSharpAuthor" Version="2.0.0-preview1002" />
                    
Directory.Packages.props
<PackageReference Include="CSharpAuthor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CSharpAuthor --version 2.0.0-preview1002
                    
#r "nuget: CSharpAuthor, 2.0.0-preview1002"
                    
#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.
#:package CSharpAuthor@2.0.0-preview1002
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CSharpAuthor&version=2.0.0-preview1002&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CSharpAuthor&version=2.0.0-preview1002&prerelease
                    
Install as a Cake Tool

CSharpAuthor

Programmatically generate C# source. Built for Roslyn source generators, where it is about 25× faster than SyntaxFactory + NormalizeWhitespace — 0.019 ms against 0.489 ms per file, measured on the same machine in the same run.

You build a tree of definitions; it emits formatted C#. Types stay unrendered until the whole file is known, so namespaces are derived from what you actually wrote rather than declared on the side.

var file = new CSharpFileDefinition("TestNamespace");

var classDefinition = file.AddClass("TestClass");

var method = classDefinition.AddMethod("SomeMethod");

classDefinition.AddUsingNamespace("SomeNamespace");

var outputContext = new OutputContext();

file.WriteOutput(outputContext);

var outputString = outputContext.Output();
using SomeNamespace;

namespace TestNamespace
{
    public class TestClass
    {

        public void SomeMethod()
        {
        }
    }
}

Install

dotnet add package CSharpAuthor

CSharpAuthor ships as source, compiled into your project, so a source generator can use it without taking on a dependency it would then have to redistribute. Set PackageCSharpAuthorIncludeSource=true in a generator project.

An optional Roslyn bridge — ITypeSymbol → ITypeDefinition, and attribute reading — ships in the same package behind PackageCSharpAuthorIncludeRoslyn=true. Your generator already references Roslyn, so it costs nothing extra.

Why the type model matters

ITypeDefinition is not a string. It stays unrendered until serialization, which is what lets one option flip an entire file between short names and global::, resolve same-name collisions with an alias, and make a missing using structurally impossible.

var options = new OutputContextOptions { TypeOutputMode = TypeOutputMode.Global };

Global qualifies every reference and emits no derived usings — the recommended default for a generator, and the faster path. ShortName gives you shorter names, derived using directives and automatic collision aliasing.

Targeting a language version

The tree is version-agnostic; the writer decides how to render it. An EmitProfile says what the target may use, and features downlevel where an equivalent exists — a collection expression becomes new[] { … } below C# 12, silently and correctly. Where no equivalent exists, you get a diagnostic rather than wrong output.

Documentation

License

MIT. See LICENSE.

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

Version Downloads Last Updated
2.0.0 1,720 9/6/2026
2.0.0-preview1005 2,123 8/28/2026
2.0.0-preview1004 171 8/22/2026
2.0.0-preview1003 131 8/22/2026
2.0.0-preview1002 115 8/21/2026
2.0.0-preview1001 118 8/21/2026
2.0.0-preview1000 114 8/21/2026
1.2.0 313 8/21/2026
1.1.1010 478 8/14/2026
1.1.1009 157 8/13/2026
1.1.1008 135 8/13/2026
1.1.1007 267 8/8/2026
1.1.1006 874 4/27/2025
1.1.1005 258 4/26/2025
1.1.1004 292 4/14/2025
1.1.1003 304 4/13/2025
1.1.1002 201 4/12/2025
1.1.1001 310 3/19/2025
1.0.9 215 3/14/2025
1.0.8 240 3/13/2025
Loading failed