Skip to content

Repository files navigation

Purview.SourceGeneratorFramework

A set of libraries for building and testing incremental C# source generators using Roslyn.

Packages

Package Description Packable
Purview.SourceGeneratorFramework Core helpers, models, and MSBuild integration for writing incremental source generators. Yes
Purview.SourceGeneratorFramework.Testing Framework-agnostic test runner and assertions for source generator unit tests. Yes
Purview.SourceGeneratorFramework.Testing.TUnit TUnit-specific test base classes and assertions for source generator tests. Yes
SourceGeneratorFramework.Testing.Generators Internal Roslyn source generator used by the framework package. No
SourceGeneratorFramework.ExampleGenerator Reference implementation showing how to build a generator with the framework. No

Requirements

  • .NET SDK 8.0 or later
  • The test projects target net8.0, net9.0, and net10.0
  • Source generators target netstandard2.0

Building

Restore and build the solution using the just recipes or dotnet directly:

just build
# or
dotnet build src/SourceGeneratorFramework.slnx -c Release

Running tests

just tests
# or
dotnet test src/SourceGeneratorFramework.slnx -c Release

Generators

AttributeDataModelGenerator

The framework package includes AttributeDataModelGenerator (implemented in SourceGeneratorFramework.Testing.Generators), which generates readonly record struct parser models for .NET attributes. It removes the repetitive boilerplate of hand-writing FromAttributeData methods for every attribute you want to inspect in a source generator.

Supported features:

  • Manual mapping of named arguments, constructor arguments by index, and constructor arguments by name
  • Auto-discovery of all constructor parameters and public named properties
  • Nested generated models (e.g., a shared ValidationAttributeData model reused inside RequiredAttributeData)
  • Inheritance matching for base attribute models
  • Optional DefaultValue runtime fallback when a property is not found on the attribute
  • An Empty sentinel that uses default(T) for every property

See the SourceGeneratorFramework.Testing.Generators README for examples, including validation attributes with nested types.

Packaging

just pack
# or
dotnet pack src/SourceGeneratorFramework.slnx -c Release -o ./artifacts

License

This project is licensed under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages