Deepstaging.Roslyn
1.0.0-dev-20260206052740
dotnet add package Deepstaging.Roslyn --version 1.0.0-dev-20260206052740
NuGet\Install-Package Deepstaging.Roslyn -Version 1.0.0-dev-20260206052740
<PackageReference Include="Deepstaging.Roslyn" Version="1.0.0-dev-20260206052740" />
<PackageVersion Include="Deepstaging.Roslyn" Version="1.0.0-dev-20260206052740" />
<PackageReference Include="Deepstaging.Roslyn" />
paket add Deepstaging.Roslyn --version 1.0.0-dev-20260206052740
#r "nuget: Deepstaging.Roslyn, 1.0.0-dev-20260206052740"
#:package Deepstaging.Roslyn@1.0.0-dev-20260206052740
#addin nuget:?package=Deepstaging.Roslyn&version=1.0.0-dev-20260206052740&prerelease
#tool nuget:?package=Deepstaging.Roslyn&version=1.0.0-dev-20260206052740&prerelease
Deepstaging.Roslyn
Roslyn APIs are powerful but awkward. This library wraps them in something that feels natural.
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
Related Packages
- Testing - Test infrastructure for Roslyn components
- Scriban Templates - Template infrastructure for source generators
- Workspace / Code Fixes - Code fix provider infrastructure
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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 5.0.0)
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.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-dev-20260206052740 | 0 | 2/6/2026 |
| 1.0.0-dev-20260206052300 | 0 | 2/6/2026 |
| 1.0.0-dev-20260206052010 | 0 | 2/6/2026 |
| 1.0.0-dev-20260206051548 | 0 | 2/6/2026 |
| 1.0.0-dev-20260205052640 | 19 | 2/5/2026 |
| 1.0.0-dev-20260205050756 | 22 | 2/5/2026 |
| 1.0.0-dev-20260204225221 | 30 | 2/4/2026 |
| 1.0.0-dev-20260204225018 | 28 | 2/4/2026 |
| 1.0.0-dev-20260204223024 | 25 | 2/4/2026 |
| 1.0.0-dev-20260204222744 | 27 | 2/4/2026 |
| 1.0.0-dev-20260204221656 | 23 | 2/4/2026 |
| 1.0.0-dev-20260204221327 | 33 | 2/4/2026 |
| 1.0.0-dev-20260204221227 | 28 | 2/4/2026 |
| 1.0.0-dev-20260204221019 | 28 | 2/4/2026 |
| 1.0.0-dev-20260204220308 | 32 | 2/4/2026 |