This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ScopedAction is a .NET library that provides an abstract base class implementing the RAII (Resource Acquisition Is Initialization) pattern. It executes paired actions at the beginning and end of code blocks using C#'s using statement and IDisposable pattern.
# Build the library
dotnet build
# Build with Release configuration
dotnet build --configuration Release
# Run all tests
dotnet test
# Run a specific test by name
dotnet test --filter "FullyQualifiedName~ScopedActionTests.ActionExecutionOrder_IsCorrect"
# Create NuGet package
dotnet pack --configuration Release --output ./stagingThe library consists of a single abstract class (ScopedAction/ScopedAction.cs) that:
- Implements
IDisposablewith the standard dispose pattern - Provides two protected constructors:
ScopedAction(Action? onOpen, Action? onClose)- ExecutesonOpenimmediately, storesonClosefor disposalScopedAction()- Parameterless for custom initialization patterns
- Exposes
OnCloseas a protected settable property for derived classes - Ensures
OnCloseexecutes only once viadisposedValueflag
Derived classes use three patterns (see README.md for examples):
- Method Groups: Static methods without parameters passed directly to base constructor
- Lambda Capture: Lambdas capturing constructor parameters for static methods
- Instance Members: Parameterless constructor with
OnCloseproperty assignment for stateful cleanup
ScopedAction/- Main library (multi-targeted: net10.0, net9.0, net8.0, net7.0, net6.0, net5.0, netstandard2.1, netstandard2.0)ScopedAction.Tests/- MSTest tests (targets net10.0 only)- Uses
ktsu.Sdkfor standardized build configuration - Uses Central Package Management via
Directory.Packages.props
Tests use MSTest.Sdk with Microsoft.Testing.Platform runner. Key test scenarios:
- OnOpen executes immediately on construction
- OnClose executes on disposal (only once)
- Null actions are handled gracefully
- Exception safety (cleanup runs even with exceptions)
- Execution order verification