Skip to content

ToStringGenerator: Add struct support #147

@BoBoBaSs84

Description

@BoBoBaSs84

Is your feature request related to a problem? Please describe.
The ToStringGenerator currently only supports classes via ClassDeclarationSyntax. Structs cannot benefit from the generated ToString() override, even though structs also have a default ToString() implementation that is often inadequate (uses reflection, poor performance).

Describe the solution you'd like
Extend the ToStringGenerator to support struct types in addition to classes. This would require:

  • Updating GenerateToStringAttribute to target AttributeTargets.Class | AttributeTargets.Struct.
  • Using TypeDeclarationSyntax instead of ClassDeclarationSyntax in the pipeline.
  • Generating partial struct declarations when the target is a struct.

Describe alternatives you've considered

  • A separate GenerateStructToString attribute, but this adds unnecessary API surface.
  • Manual ToString() implementations for structs, but this defeats the purpose of the generator.

Additional context
Struct ToString() via reflection is notoriously slow. A generated implementation would provide a significant performance improvement for value types.

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions