loach.PureSharp
1.0.0
See the version list below for details.
dotnet add package loach.PureSharp --version 1.0.0
NuGet\Install-Package loach.PureSharp -Version 1.0.0
<PackageReference Include="loach.PureSharp" Version="1.0.0" />
<PackageVersion Include="loach.PureSharp" Version="1.0.0" />
<PackageReference Include="loach.PureSharp" />
paket add loach.PureSharp --version 1.0.0
#r "nuget: loach.PureSharp, 1.0.0"
#:package loach.PureSharp@1.0.0
#addin nuget:?package=loach.PureSharp&version=1.0.0
#tool nuget:?package=loach.PureSharp&version=1.0.0
PureSharp
English | 日本語 | 简体中文 | 繁體中文 | Esperanto | Klingon | Español | Français | Deutsch | 한국어
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
- Purity enforcement: declare side-effect-free logic with
[PureMethod]and verify the documented v1 subset mechanically. - Immutable locals: opt into non-reassignable local variables by starting their names with
_. - Safe control flow: use
Fluent.Ifchains 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
docs/GETTING_STARTED.md— clean consumer Quick Start.docs/DIAGNOSTICS.md— diagnostic SSOT and compatibility policy.docs/RULE-EXAMPLES.md— all seven diagnostics with examples.docs/PURITY-SEMANTICS.md— RT semantics and known limitations.docs/CALL-CONTRACT.md—[PureMethod]call rules.docs/LVP.md— immutable-local contract.docs/FLUENT_IF.md— FluentIf contract.docs/COMPATIBILITY.md— supported versions and performance policy.docs/DOCUMENTATION.md— documentation/translation SSOT policy.CONTRIBUTING.md— contribution workflow.
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 | 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
- 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.