CsEffect.Analyzer 0.15.0

dotnet add package CsEffect.Analyzer --version 0.15.0
                    
NuGet\Install-Package CsEffect.Analyzer -Version 0.15.0
                    
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="CsEffect.Analyzer" Version="0.15.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CsEffect.Analyzer" Version="0.15.0" />
                    
Directory.Packages.props
<PackageReference Include="CsEffect.Analyzer">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 CsEffect.Analyzer --version 0.15.0
                    
#r "nuget: CsEffect.Analyzer, 0.15.0"
                    
#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 CsEffect.Analyzer@0.15.0
                    
#: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=CsEffect.Analyzer&version=0.15.0
                    
Install as a Cake Addin
#tool nuget:?package=CsEffect.Analyzer&version=0.15.0
                    
Install as a Cake Tool

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 attributes
  • EffectTargetsAttribute - Specifies which types trigger the effect requirement
  • EffectSeverityAttribute - 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

  1. Define your effect attribute:

    [EffectTargets(typeof(MyEffectfulApi))]
    [EffectSeverity(EffectViolationLevel.Error)] // Optional: make violations errors
    public sealed class MyEffectAttribute : EffectAttribute
    {
    }
    
  2. Annotate your effectful methods:

    [MyEffect]
    public void DoSomethingEffectful()
    {
        MyEffectfulApi.DoSomething();
    }
    
  3. 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

There are no supported framework assets in this package.

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