Skip to content

Keep type parameters when implementing properties of a generic class (v10.x) - #5044

Merged
rockfordlhotka merged 3 commits into
v10.xfrom
issue-5042/v10-cslaimplementproperties-generic-types
Nov 20, 2026
Merged

rockfordlhotka merged 3 commits into
v10.xfrom
issue-5042/v10-cslaimplementproperties-generic-types

Conversation

@rockfordlhotka

@rockfordlhotka rockfordlhotka commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Backports #5043 to v10.x for 10.3.0. [CslaImplementProperties] and [CslaImplementPropertiesInterface<T>] on a generic partial class such as PersonBase<T> generated partial class PersonBase, a separate non-generic type, so the partial properties were never implemented.

  • The generated partial declaration repeats the class's type parameters (partial class PersonBase<T>). It writes names only; constraints and type-parameter attributes are left out, which a partial declaration allows.
  • A generic class's hint name gets an arity suffix (PersonBase-1.g.cs), so Foo and Foo<T> don't collide. (The review follow-ups below also add the namespace to every hint name.)
  • A property whose type is a class type parameter (T, T?) is generated with that type. Before, it was written with an empty type.
  • v10.x only: the base class that chooses GetProperty/SetProperty/LoadProperty/ReadProperty is now the nearest Csla base class, found through any intermediate base classes. Before, only the direct base class's name was checked for BusinessBase, ReadOnlyBase or CommandBase, which is why renaming PersonBase to PersonBusinessBase worked around the bug in the issue. main already has this lookup.

Review follow-ups

  • Hint names now include the namespace and containing types (Sales.Order.g.cs, Test.Outer-1.Line.g.cs). Before, same-named classes in different namespaces made AddSource throw, and the generator produced nothing for the whole project. Existing snapshots are renamed only; their content is unchanged.
  • Nested types: a [CslaImplementProperties] class nested in other types is generated inside partial declarations of those types, with their type parameters.
  • Array types are displayed from the array symbol, so T[][] and int[,] keep every rank. Keyword identifiers such as @class are escaped.
  • [AutoSerializable] had the same bug: a generic type, or one nested in a generic type, lost its type parameters. It now keeps them, members typed as a type parameter (T, T?, T[]) are serialized with that type, and its hint names use the arity.
  • New tests: type-parameter shapes (struct-constrained T?, T[], jagged and multi-dimensional arrays, @class), nested-in-generic, same name in different namespaces, an interface in another file, and generic [AutoSerializable] types. All fail without the fixes.
  • Arity separator: generic hint names put - before the arity (Foo-1). - can't occur in an identifier, so Foo<T> no longer collides with a class named Foo_1, as the target or as a containing type.
  • v10.x only:
    • [CslaImplementPropertiesInterface<T>] binds an interface declared in another file with that file's semantic model. Before, it threw.
    • The property methods come from a single CslaBaseClasses map, as on main. A class with no CSLA base class in its chain now gets nothing generated. Before, it got code calling GetProperty/SetProperty, which its base class doesn't have.

Test plan

  • New snapshot tests: a generic class with an intermediate generic base and string/T? properties; Pair and Pair<TKey, TValue> in one compilation; an intermediate base class whose name doesn't contain the CSLA base class's name; and a generic class with [CslaImplementPropertiesInterface<T>]
  • Confirmed all 4 new tests fail without the generator change
  • Csla.Generator.AutoImplementProperties.CSharp.Tests passes with the .NET 10 SDK (78 tests), and Csla.Generator.AutoSerialization.CSharp.Tests (99 tests)
  • Full csla.test.sln suite passes locally (TestCategory!=SkipOnCIServer)

Backport for #5042 (main fix: #5043)

🤖 Generated with Claude Code

rockfordlhotka and others added 3 commits November 16, 2026 11:21
…class (v10.x)

Backport of the main fix, plus the base class lookup the reporter worked
around by renaming their base class.

- The generated partial declaration repeats the class's type parameters
  (names only; a partial declaration may omit constraints). Before, a
  generic PersonBase<T> got "partial class PersonBase", a different type.
- The hint name of a generic class gets an arity suffix (PersonBase_1.g.cs)
  so Foo and Foo<T> don't collide. Non-generic hint names are unchanged.
- A property whose type is a type parameter (T, T?) is generated with that
  type; it used to be written with an empty type.
- The base class used to choose GetProperty/SetProperty/LoadProperty/
  ReadProperty is the nearest Csla base class through any intermediate
  base classes. Before, only the direct base class's name was checked, so
  nothing was generated unless that name contained "BusinessBase",
  "ReadOnlyBase" or "CommandBase". When no Csla base class is found, the
  direct base class's name is used, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ators (v10.x)

AutoImplementProperties generator:
- Hint names include the namespace and containing types (Sales.Order.g.cs),
  so same-named classes in different namespaces no longer collide and
  abort the generator. Existing snapshots are renamed accordingly.
- A class nested in other types is generated inside partial declarations
  of its containing types, with their type parameters.
- [CslaImplementPropertiesInterface<T>] binds an interface declared in
  another file with that file's semantic model instead of throwing.
- Array property types are displayed from the array symbol, so jagged and
  multi-dimensional arrays keep every rank; keyword identifiers such as
  @Class are escaped.
- One CslaBaseClasses map chooses the property methods. A class whose
  base chain has no CSLA base class gets nothing generated, instead of
  code calling methods its base class doesn't have.

AutoSerialization generator:
- A generic [AutoSerializable] type, and one nested in a generic type,
  keeps its type parameters; hint names use the arity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er members

- Generic types' hint names use '-' before the arity (Test.Foo-1.g.cs),
  which can't occur in an identifier, so Foo<T> no longer shares a hint
  name with a class named Foo_1, as a target or a containing type, in
  both the property and serialization generators.
- The serialization generator writes members typed as a type parameter
  (T, T?, T[]) with that type instead of an empty one, and displays array
  types from the array symbol.
- Tests for the hint-name collisions and for type-parameter members of a
  generic [AutoSerializable] class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rockfordlhotka
rockfordlhotka merged commit 5e0d27b into v10.x Nov 20, 2026
2 checks passed
@rockfordlhotka
rockfordlhotka deleted the issue-5042/v10-cslaimplementproperties-generic-types branch November 20, 2026 19:51
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.

1 participant