Skip to content

Make With extension methods and let Func map to another type [major] - #85

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/issue-76-extension-methods
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/issue-76-extension-methods

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Summary

DelegateTransform.With(...) didn't compile from any other ktsu.* namespace. There the simple name DelegateTransform resolves to the namespace ktsu.DelegateTransform, not the class, so the call fails with CS0234. The README's mapping example didn't compile anywhere either. This PR implements the maintainer decision on the issue.

  • Extension methods. All three With overloads now take this T input. Callers write input.With(...), which never names the type, and chaining works as the docs describe.
  • Mapping overload. With<T>(T, Func<T, T>) is replaced by With<T, TResult>(T, Func<T, TResult>).
    • Keeping both makes every lambda call ambiguous (CS0121, confirmed while building).
    • TResult infers to T for same-type functions, so existing Func call sites bind to the new overload unchanged.
  • Consumer-namespace test. ConsumerNamespaceTests.cs lives in ktsu.Consumer and compiles the README examples: ActionRef, Func, FuncRef, fluent chaining, mapping to string, and the null check on the new overload.
  • Docs. README and CLAUDE.md now use the extension form, with a note on why the type-qualified form fails.
  • Test cleanup. One existing null-delegate test now uses a typed local instead of a cast. With the new overload set, IDE0004 flags that cast as redundant, and the analyzer treats that as an error.

This is a breaking API change: the Func<T, T> overload is removed and the methods gain this. It ships as major, per the decision on the issue.

Verification

  • With the library unchanged, the new test file fails to compile (CS1061: no With on int/string/Person).
  • With the fix, dotnet test passes 12/12 (6 existing, 6 new).
  • dotnet build -c Release passes across every target framework (net10.0 through net6.0 and netstandard2.1).

Fixes #76

🤖 Generated with Claude Code

https://claude.ai/code/session_01CTnJ1xEhZzPB9o25LiPf2C


Generated by Claude Code

DelegateTransform.With(...) failed with CS0234 from any other ktsu.*
namespace, where the simple name resolves to the namespace
ktsu.DelegateTransform rather than the class. Make the three With
overloads extension methods so callers write input.With(...), which
never names the type and chains fluently as the docs describe.

Replace With<T>(T, Func<T, T>) with With<T, TResult>(T, Func<T, TResult>)
so the README's mapping example compiles. Keeping both would make every
lambda call ambiguous (CS0121); TResult infers to T for same-type
functions, so existing Func calls bind to the new overload.

Add ConsumerNamespaceTests in ktsu.Consumer, which compiles the README
examples from outside the library's namespace so the clash cannot
return, and update the README and CLAUDE.md to the extension form.

Fixes #76

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CTnJ1xEhZzPB9o25LiPf2C
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 27b1130 into main Oct 9, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the claude/issue-76-extension-methods branch October 9, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DelegateTransform.With(...) fails to compile (CS0234) from any code in a ktsu.* namespace, and the README's mapping example can't compile anywhere

2 participants