Skip to content

Add XPC3007: suggest type-safe Custom API handler overload#20

Merged
mkholt merged 2 commits into
mainfrom
suggest-using-nameof-for-customapi-236
Jul 3, 2026
Merged

Add XPC3007: suggest type-safe Custom API handler overload#20
mkholt merged 2 commits into
mainfrom
suggest-using-nameof-for-customapi-236

Conversation

@mkholt

@mkholt mkholt commented Jul 3, 2026

Copy link
Copy Markdown
Member

When a Custom API declares AddRequestParameter/AddResponseProperty but registers with the action-based RegisterAPI(name, Action) overload, XPC3007 (Info) now suggests the type-safe RegisterAPI(name, nameof(TService.Handler)) overload that generates strongly-typed request/response DTOs, mirroring the type-safe image support for plugin steps. Includes a code fix that converts the lambda to nameof(...), after which XPC4005/XPC4006 guide the handler signature.

Also:

  • Move the already-shipped Custom API rules (XPC3006/XPC4004/XPC4005/XPC4006) from AnalyzerReleases.Unshipped.md to Shipped.md under Release 1.4.1.
  • Mark the pending CHANGELOG entry as "v1.4.2 - Unreleased" and document the unreleased-entry and analyzer release-tracking conventions in CLAUDE.md.

When a Custom API declares AddRequestParameter/AddResponseProperty but
registers with the action-based RegisterAPI<TService>(name, Action<TService>)
overload, XPC3007 (Info) now suggests the type-safe
RegisterAPI<TService>(name, nameof(TService.Handler)) overload that generates
strongly-typed request/response DTOs, mirroring the type-safe image support
for plugin steps. Includes a code fix that converts the lambda to nameof(...),
after which XPC4005/XPC4006 guide the handler signature.

Also:
- Move the already-shipped Custom API rules (XPC3006/XPC4004/XPC4005/XPC4006)
  from AnalyzerReleases.Unshipped.md to Shipped.md under Release 1.4.1.
- Mark the pending CHANGELOG entry as "v1.4.2 - Unreleased" and document the
  unreleased-entry and analyzer release-tracking conventions in CLAUDE.md.

Co-Authored-By: Claude <noreply@anthropic.com> via Conducktor <conducktor@contextand.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a new analyzer rule (XPC3007) and code fix to nudge Custom API registrations toward the type-safe RegisterAPI<TService>(name, nameof(...)) overload when request/response parameters are declared, and updates release/docs tracking to reflect shipped vs. unreleased analyzer rules.

Changes:

  • Add XPC3007 analyzer + code fix to convert action-lambda registrations to nameof(...) for typed Custom API handlers when parameters/properties are declared.
  • Add rule documentation for XPC3007 and expand unit tests to cover the new diagnostic and code fix.
  • Update analyzer release tracking files and document changelog + analyzer-release conventions.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
XrmPluginCore/CHANGELOG.md Adds v1.4.2 “Unreleased” entry documenting XPC3007.
XrmPluginCore.SourceGenerator/rules/XPC3007.md New rule documentation and examples for XPC3007.
XrmPluginCore.SourceGenerator/Helpers/RegisterApiHelper.cs Adds action-overload detection and lambda-method-name extraction helper.
XrmPluginCore.SourceGenerator/DiagnosticDescriptors.cs Adds descriptor for new XPC3007 rule.
XrmPluginCore.SourceGenerator/CodeFixes/PreferTypedCustomApiHandlerCodeFixProvider.cs New code fix provider converting lambda argument to nameof(...).
XrmPluginCore.SourceGenerator/Analyzers/PreferTypedCustomApiHandlerAnalyzer.cs New analyzer that reports XPC3007 for action-overload registrations with declared params/properties.
XrmPluginCore.SourceGenerator/AnalyzerReleases.Unshipped.md Moves previously shipped rules out; adds XPC3007 as unshipped.
XrmPluginCore.SourceGenerator/AnalyzerReleases.Shipped.md Records XPC3006/XPC4004-6 as shipped in release 1.4.1.
XrmPluginCore.SourceGenerator.Tests/DiagnosticTests/CustomApiHandlerDiagnosticsTests.cs Adds tests for XPC3007 diagnostic and code fix behavior.
CLAUDE.md Documents new rule and release/changelog conventions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread XrmPluginCore.SourceGenerator/Helpers/RegisterApiHelper.cs
Comment thread XrmPluginCore.SourceGenerator/DiagnosticDescriptors.cs
- GetActionMethodName: only extract the handler name when the lambda calls a
  method directly on the service parameter (s => s.Handle()), not on a different
  receiver (s => Other.Handle()) or a nested access (s => s.Foo.Handle()), so the
  code fix never offers a misleading nameof(TService.X).
- CreateNameofExpression: parse the service type as a name so qualified
  (My.Namespace.Service) and generic (Service<T>) type names produce valid nameof
  syntax. This also fixes the shipped XPC3001 code fix, which shares the helper.
- XPC3007 message: drop the hardcoded ".Handler" and recommend the typed overload
  with nameof(...) without implying a specific method name.
- Tests + CHANGELOG updated accordingly.

Co-Authored-By: Claude <noreply@anthropic.com> via Conducktor <conducktor@contextand.com>
@mkholt mkholt merged commit aad1d66 into main Jul 3, 2026
1 check passed
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.

2 participants