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.
Is your feature request related to a problem? Please describe.
The
ToStringGeneratorcurrently only supports classes viaClassDeclarationSyntax. Structs cannot benefit from the generatedToString()override, even though structs also have a defaultToString()implementation that is often inadequate (uses reflection, poor performance).Describe the solution you'd like
Extend the
ToStringGeneratorto supportstructtypes in addition to classes. This would require:GenerateToStringAttributeto targetAttributeTargets.Class | AttributeTargets.Struct.TypeDeclarationSyntaxinstead ofClassDeclarationSyntaxin the pipeline.partial structdeclarations when the target is a struct.Describe alternatives you've considered
GenerateStructToStringattribute, but this adds unnecessary API surface.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.