CsEffect.Analyzer
0.15.0
dotnet add package CsEffect.Analyzer --version 0.15.0
NuGet\Install-Package CsEffect.Analyzer -Version 0.15.0
<PackageReference Include="CsEffect.Analyzer" Version="0.15.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="CsEffect.Analyzer" Version="0.15.0" />
<PackageReference Include="CsEffect.Analyzer"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add CsEffect.Analyzer --version 0.15.0
#r "nuget: CsEffect.Analyzer, 0.15.0"
#:package CsEffect.Analyzer@0.15.0
#addin nuget:?package=CsEffect.Analyzer&version=0.15.0
#tool nuget:?package=CsEffect.Analyzer&version=0.15.0
CsEffect.Analyzer
A Roslyn analyzer for tracking and propagating effect annotations in C# codebases.
Overview
CsEffect.Analyzer is the core component of the CsEffect system that provides compile-time analysis to ensure proper effect annotation propagation throughout your codebase. It helps you document and track side effects in your APIs by requiring explicit effect annotations on methods that perform or call effectful operations.
What it does
- Tracks effect propagation: Analyzes method calls to ensure that effectful operations are properly annotated
- Validates effect hierarchies: Supports effect inheritance where more general effects can satisfy more specific ones
- Interface validation: Ensures interface implementations don't introduce effects not declared on the interface
- Configurable severity: Effect authors can choose between warnings and errors for violations
Key Features
Effect Base Classes
EffectAttribute- Base class for all effect attributesEffectTargetsAttribute- Specifies which types trigger the effect requirementEffectSeverityAttribute- Controls whether violations are warnings or errors
Diagnostics
- CSE001: Effect usage requires annotation - triggered when calling effectful APIs without proper attributes
- CSE002: Interface implementation effect mismatch - triggered when implementations add effects not on interfaces
Special Handling
- Top-level statements: Automatically excluded from analysis since they cannot be annotated
- Implicitly declared methods: Compiler-generated methods are ignored
Usage
Reference this package as an analyzer in your project:
<ItemGroup>
<PackageReference Include="CsEffect.Analyzer" Version="0.2.0" OutputItemType="Analyzer" />
</ItemGroup>
Or for project references:
<ItemGroup>
<ProjectReference Include="path\to\CsEffect.Analyzer.csproj" OutputItemType="Analyzer" />
</ItemGroup>
Creating Custom Effects
Define your effect attribute:
[EffectTargets(typeof(MyEffectfulApi))] [EffectSeverity(EffectViolationLevel.Error)] // Optional: make violations errors public sealed class MyEffectAttribute : EffectAttribute { }Annotate your effectful methods:
[MyEffect] public void DoSomethingEffectful() { MyEffectfulApi.DoSomething(); }The analyzer will require callers to be annotated:
[MyEffect] // Required by analyzer public void Caller() { DoSomethingEffectful(); }
Effect Hierarchies
Effects can inherit from each other to create hierarchies:
public class IoEffectAttribute : EffectAttribute { } // General I/O
[EffectTargets(typeof(Console))]
public sealed class ConsoleEffectAttribute : IoEffectAttribute { } // Specific console I/O
Methods annotated with [IoEffect] can call methods that require [ConsoleEffect], but not vice versa.
License
MIT
Learn more about Target Frameworks and .NET Standard.
This package has 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 |
|---|---|---|
| 0.15.0 | 165 | 10/13/2025 |
| 0.14.0 | 163 | 10/13/2025 |
| 0.13.0 | 162 | 10/13/2025 |
| 0.12.0 | 163 | 10/13/2025 |
| 0.11.0 | 163 | 10/13/2025 |
| 0.10.0 | 169 | 10/12/2025 |
| 0.9.0 | 166 | 10/12/2025 |
| 0.8.0 | 165 | 10/12/2025 |
| 0.7.0 | 162 | 10/12/2025 |
| 0.6.0 | 145 | 10/12/2025 |
| 0.5.0 | 145 | 10/12/2025 |
| 0.4.0 | 148 | 10/12/2025 |
| 0.3.0 | 104 | 10/11/2025 |
| 0.2.0 | 106 | 10/11/2025 |
| 0.2.0-alpha.12 | 64 | 10/11/2025 |
| 0.2.0-alpha.11 | 47 | 10/10/2025 |
| 0.1.0 | 204 | 10/10/2025 |
| 0.0.0 | 101 | 10/11/2025 |