ShadowWriter

May 10, 2026 · View on GitHub

NuGet License: MIT Build

ShadowWriter is a Roslyn Source Generator designed to simplify and automate aspects of .NET development.
It currently supports the following features:

✨ Features

Samples can be found in the Source-Code or in the Documentation.

1. Generate Null Objects

The NullObject feature in ShadowWriter provides a simple way to automatically generate null object implementations for interfaces and classes. This pattern is useful for providing default "do nothing" implementations that can help avoid null reference exceptions and simplify code.

Usage

To create a null object implementation, simply add the [NullObject] attribute to your class:

[NullObject]
public partial class ImplementingMyInterface : IMyInterface
{
}

2. Inject Project Information

Embeds values from the project file (*.csproj) directly into your source code.
This is useful for build metadata, version numbers, or project-specific configuration.

Available Properties

The generated ProjectInfo class provides the following static properties:

Enabling the Generator

The generator is opt-in and must be enabled in your .csproj file:

<PropertyGroup>
  <ShadowWriter_EnableProjectInfo>true</ShadowWriter_EnableProjectInfo>
</PropertyGroup>
PropertyDescriptionExample
FullPathThe complete path to the project file/path/to/YourProject.csproj
ProjectDirectoryThe directory containing the project file/path/to/
NameThe name of the projectYourProject
OutDirThe output directory for compiled artifacts/path/to/artifacts/bin/YourProject/debug/
VersionThe current version of the project1.0.0
RootNamespaceThe root namespace of the projectYourProject

Example Usage

// Access project information anywhere in your code 
Console.WriteLine($"Project Name: {ProjectInfo.Name}"); 
Console.WriteLine($"Project Version: {ProjectInfo.Version}"); 
Console.WriteLine($"Project Output Directory: {ProjectInfo.OutDir}");

3. Experimental: Typed Access to EmbeddedResources

Generates strongly typed wrappers for EmbeddedResources, allowing safe and convenient access to resources at runtime.

⚠️ Feature #3 is experimental and may change significantly in future versions.

Details can be found in the Wiki.

4. Generate Builders for Records

The Builder feature automatically generates a nested Builder class for any partial record annotated with [Builder]. Each parameter becomes a nullable property, and Build() validates that all non-nullable parameters are set before constructing the record.

[Builder]
public partial record Order(int Quantity, string? Note);

var order = new Order.Builder { Quantity = 3 }.Build();

See Builder documentation for full details, generated code examples, and validation rules.

📦 Installation

You can install ShadowWriter via NuGet:

dotnet package add ShadowWriter

⚙️ Usage

ShadowWriter runs automatically during compilation. No manual setup is needed. Documentation and configuration options will be expanded in future versions.

📄 License

This project is licensed under the MIT License.