Skip to content

Read a module's parameters and equality from its own members, and skip modules DM0003 or DM0017 rejects - #106

Merged
ipjohnson merged 1 commit into
mainfrom
fix/module-declaration
Sep 24, 2026
Merged

ipjohnson merged 1 commit into
mainfrom
fix/module-declaration

Conversation

@ipjohnson

Copy link
Copy Markdown
Owner

Closes #68. Closes #71. Closes #72.

The generator now reads a module's parameters and equality members from the module itself, and it writes no code for a module that DM0003 or DM0017 rejects. All three issues gave generated code that did not compile, or DM0018 for a module that did not need it.

#68: module parameters

GetAttributeClassInfo walked DescendantNodes, so each settable property of a class nested in the module became a parameter of the module attribute. It now reads only the direct members of the module declaration.

A property now counts as a parameter only when the generated attribute can use its set accessor. A private set or protected set is left out. An internal set or protected internal set is kept. A set accessor with no modifier has the access of its property, as before.

Both repros in the issue now compile. OptionsModule no longer gets DM0018, because it has no parameter.

#71: equality

GetEqualsFlag looked at the declaration that has [DependencyModule], and it took any method named Equals. GetEqualityFeatures now reads the symbol, so a member in any partial declaration counts:

  • A module that declares Equals(object) gets no generated Equals or GetHashCode, as before. DM0018 is not reported.
  • A module that declares only Equals for its own type gets a generated Equals(object) that calls it: obj is AuditModule other && Equals(other). The load operation calls Equals(object), so the module's own equality now decides which instances are the same. DM0018 is not reported for such a module.
  • GetHashCode is generated only when the module declares none. Before, a module with its own GetHashCode and no Equals got CS0111.

Two new ModuleEntryPointFeatures flags carry this: ShouldImplementGetHashCode and DeclaresTypedEquals.

#72: rejected modules

EntryModelUtil.RegistrationTargets now leaves out a module that is not partial or is nested in another type. The service, interceptor, decorator and convention writers all filter through it, so none of them writes a partial class for such a module. The build then reports only DM0003 or DM0017.

Public API

The DependencyModules.SourceGenerator snapshot adds the two ModuleEntryPointFeatures values.

Docs

The warnings for #68, #71 and #72 are on docs-ste-rewrite, in modules.md, getting-started.md and diagnostics.md. They will be removed in one docs pass after the fixes.

Verified

🤖 Generated with Claude Code

…p modules DM0003 or DM0017 rejects

A property with a private set accessor became a module parameter, and so did every settable
property of a class nested in the module. Both gave generated code that did not compile. Only
the module's own properties count now, and the set accessor must be one the attribute can use.

The Equals check looked at one declaration and took any method named Equals. It now reads the
symbol, so Equals and GetHashCode in another partial declaration count. A module that declares
only Equals for its own type gets a generated Equals(object) that calls it, and GetHashCode is
generated only when the module has none.

RegistrationTargets now leaves out a module that is not partial or is nested, so no writer
emits a partial class for it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ipjohnson
ipjohnson force-pushed the fix/module-declaration branch from 3c0c3eb to cad6257 Compare September 24, 2026 12:28
@ipjohnson
ipjohnson merged commit 3ce8021 into main Sep 24, 2026
2 checks 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

1 participant