Deepstaging.Roslyn 1.0.0-dev-20260206052740

This is a prerelease version of Deepstaging.Roslyn.
dotnet add package Deepstaging.Roslyn --version 1.0.0-dev-20260206052740
                    
NuGet\Install-Package Deepstaging.Roslyn -Version 1.0.0-dev-20260206052740
                    
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="Deepstaging.Roslyn" Version="1.0.0-dev-20260206052740" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Deepstaging.Roslyn" Version="1.0.0-dev-20260206052740" />
                    
Directory.Packages.props
<PackageReference Include="Deepstaging.Roslyn" />
                    
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 Deepstaging.Roslyn --version 1.0.0-dev-20260206052740
                    
#r "nuget: Deepstaging.Roslyn, 1.0.0-dev-20260206052740"
                    
#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 Deepstaging.Roslyn@1.0.0-dev-20260206052740
                    
#: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=Deepstaging.Roslyn&version=1.0.0-dev-20260206052740&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Deepstaging.Roslyn&version=1.0.0-dev-20260206052740&prerelease
                    
Install as a Cake Tool

Deepstaging.Roslyn

Roslyn APIs are powerful but awkward. This library wraps them in something that feels natural.

📚 Full Documentation

What is this?

Three things:

Query builders for finding symbols without writing loops:

TypeQuery.From(compilation)
    .ThatArePublic()
    .ThatAreClasses()
    .WithAttribute("MyAttribute")
    .GetAll()

Projections for working with nullable Roslyn data safely:

OptionalSymbol<INamedTypeSymbol> type = GetTypeOrNull();
var name = type
    .Where(t => t.IsPublic)
    .Map(t => t.FullyQualifiedName)
    .OrNull();

Emit builders for generating C# code with fluent syntax:

TypeBuilder
    .Class("Customer")
    .AddProperty("Name", "string", prop => prop
        .WithAccessibility(Accessibility.Public)
        .WithAutoPropertyAccessors())
    .Emit()

Features

  • Queries - Fluent builders for finding types, methods, properties, fields, constructors, events, and parameters
  • Projections - Optional/validated wrappers that make null-checking less painful
  • Emit - Fluent builders for generating compilable C# code
  • Extensions - Convenience methods for common Roslyn operations

Why?

Writing Roslyn analyzers and source generators means dealing with:

  • Nullable symbols everywhere
  • Casting between ISymbol types
  • Manually looping through members
  • Verbose syntax for common checks
  • Complex SyntaxFactory calls for code generation

This library doesn't hide Roslyn, it just makes it less annoying. You still get ISymbol references back when you need them, and you get valid CompilationUnitSyntax when generating code.

Installation

Reference this project in your analyzer. It targets netstandard2.0 for broad compatibility.

Quick Examples

Find all async methods that return Task:

MethodQuery.From(typeSymbol)
    .ThatAreAsync()
    .WithReturnType("System.Threading.Tasks.Task")
    .GetAll()

Get an attribute argument or fall back to default:

var maxRetries = symbol
    .GetAttribute("RetryAttribute")
    .NamedArg<int>("MaxRetries")
    .OrDefault(3);

Check if a type implements an interface:

bool isDisposable = ((INamedTypeSymbol)typeSymbol)
    .ImplementsInterface("System.IDisposable");

Generate a complete class with properties:

var result = TypeBuilder
    .Class("Customer")
    .InNamespace("MyApp.Domain")
    .AddProperty("Id", "Guid", prop => prop
        .WithAccessibility(Accessibility.Public)
        .WithAutoPropertyAccessors())
    .AddProperty("Name", "string", prop => prop
        .WithAccessibility(Accessibility.Public)
        .WithAutoPropertyAccessors())
    .Emit();

if (result.IsValid(out var validEmit))
{
    string code = validEmit.Code;  // Valid, compilable C#
}

Documentation

See the full documentation site for detailed guides and API reference.

The test project is also useful documentation - every test shows real usage.

Philosophy

This is utility code, not a framework. It should feel like Roslyn's missing standard library, not something layered on top.

When you call .GetAll(), you get an array of actual Roslyn symbols you can use normally. When you call .Emit(), you get valid CompilationUnitSyntax you can use with Roslyn's APIs.

Reading and writing are symmetric:

  • TypeQuery finds types → TypeBuilder creates types
  • ValidSymbol wraps symbols → ValidEmit wraps generated code
  • String-based filters → String-based type references
  • Fluent, immutable → Fluent, immutable

License

RPL-1.5 (Reciprocal Public License) — Real reciprocity, no loopholes.

You can use this code, modify it, and share it freely. But when you deploy it — internally or externally, as a service or within your company — you share your improvements back under the same license.

Why? We believe if you benefit from this code, the community should benefit from your improvements. That's the deal we think is fair.

Personal research and experimentation? No obligations. Go learn, explore, and build.

See LICENSE for the full legal text.

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.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Deepstaging.Roslyn:

Package Downloads
Deepstaging.Roslyn.Scriban

Scriban template infrastructure for Roslyn source generators.

Deepstaging.Roslyn.Workspace

Roslyn Workspace utilities for code fixes and refactoring.

Deepstaging.Roslyn.Testing

Testing infrastructure for Roslyn analyzers and generators. Includes TUnit base classes and Verify snapshot testing support.

GitHub repositories

This package is not used by any popular GitHub repositories.