loach.PureSharp 1.0.1

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

PureSharp

English | 日本語 | 简体中文 | 繁體中文 | Esperanto | Klingon | Español | Français | Deutsch | 한국어

CI & NuGet Upload NuGet License: MIT X (Twitter) Follow

PureSharp brings functional-programming safety to C# through Roslyn analyzers and a small runtime API. It focuses on three contracts: referential transparency, immutable local variables, and safe FluentIf termination.

Install

dotnet add package loach.PureSharp --version 1.0.0

The package contains both PureSharp.Core and the analyzer assembly. No PureSharp-specific configuration file is required; diagnostics use standard Roslyn .editorconfig settings.

For a clean-project walkthrough, use docs/GETTING_STARTED.md.

Core concepts

  1. Purity enforcement: declare side-effect-free logic with [PureMethod] and verify the documented v1 subset mechanically.
  2. Immutable locals: opt into non-reassignable local variables by starting their names with _.
  3. Safe control flow: use Fluent.If chains that must terminate with .Else(...).

Key features

[PureMethod]

using PureSharp.Core;

public static class Calculator
{
    [PureMethod]
    public static int Add(int a, int b) => a + b;
}

Inside [PureMethod], PureSharp reports static mutable-state access, non-pure method calls, and I/O according to the v1 contract. PureSharp does not claim to prove whole-program purity; see docs/PURITY-SEMANTICS.md and docs/CALL-CONTRACT.md for the exact guarantee boundary.

Immutable local variables

var _value = Calculate();
// _value = 10; // LVP0001

Underscore-prefixed locals must be initialized at declaration and cannot later be mutated through covered assignment paths. LVP0003 suggests the convention for effectively immutable locals. See docs/LVP.md.

FluentIf

var _status = Fluent.If(score >= 80, () => 1)
    .ElseIf(score >= 60, () => 2)
    .Else(0);

A chain that starts with Fluent.If(...) must reach the matching .Else(...); otherwise FIF0001 is reported. Nested chains, lambdas, generic inference, branch short-circuiting, and exception behavior are specified in docs/FLUENT_IF.md.

Supported diagnostics

Diagnostic ID Category Title Default severity
RT0001 Purity Static field access in [PureMethod] Error
RT0002 Purity Non-pure method call in [PureMethod] Error
RT0003 Purity I/O operation in [PureMethod] Error
LVP0001 Purity Reassignment to immutable local variable prohibited Error
LVP0002 Purity Mandatory initialization of immutable local variable Error
LVP0003 Naming Suggestion to apply naming convention for immutable local variable Warning
FIF0001 FluentIf FluentIf chain termination check Error

The authoritative contract is docs/DIAGNOSTICS.md. Minimal examples for every rule are in docs/RULE-EXAMPLES.md.

Diagnostic configuration

Create or update .editorconfig in the consumer project:

root = true

[*.cs]
dotnet_diagnostic.RT0001.severity = error
dotnet_diagnostic.RT0002.severity = error
dotnet_diagnostic.RT0003.severity = error
dotnet_diagnostic.LVP0001.severity = error
dotnet_diagnostic.LVP0002.severity = error
dotnet_diagnostic.LVP0003.severity = warning
dotnet_diagnostic.FIF0001.severity = error

Use normal Roslyn values (none, silent, suggestion, warning, error). For staged adoption, override individual IDs instead of enabling/disabling whole rule families through a custom mechanism.

Example:

[*.cs]
dotnet_diagnostic.LVP0003.severity = none

Compatibility and known limitations

PureSharp.Core and the analyzer target netstandard2.0; the supported compiler/Roslyn policy and measured performance gate are documented in docs/COMPATIBILITY.md.

The v1 purity analyzer intentionally has documented boundaries. A clean analysis means that no violation of the supported subset was found, not that the method has been formally proven referentially transparent. Read the purity and call-contract documents before treating analyzer silence as a stronger guarantee.

Upgrading from 0.x

See docs/MIGRATION-1.0.md. The seven diagnostic IDs remain the v1 public IDs, while v1 hardens several edge cases such as immutable-local ref/out mutation, deconstruction reassignment, and FluentIf termination analysis.

Documentation

Project structure

  • PureSharp.Core — runtime API and Roslyn analyzers, packaged from netstandard2.0.
  • PureSharp.Analyzers.Tests — analyzer/runtime contract tests (xUnit; current CI uses .NET 10).

Motivation

C# is powerful, but unintended side effects and variable reuse can make large codebases harder to reason about. PureSharp deliberately uses constraints to make those assumptions visible to the compiler and CI.

License

PureSharp is released under the MIT License.

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.
  • .NETStandard 2.0

    • 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
1.0.1 129 10/6/2026
1.0.0 120 10/2/2026
0.1.6 5,994 8/24/2026
0.1.5 157 5/1/2026
0.1.4 158 4/3/2026
0.1.3 132 4/1/2026
0.1.2 141 3/31/2026
0.1.1 126 3/30/2026
0.1.0 471 3/28/2026