Skip to content

Use Roslyn to make sure all objects inherited from EventBase and StateBase have the [GenerateSerializer] attribute #152

@arg-foo

Description

@arg-foo

User Story
As a developer, I want a Roslyn analyzer that ensures every class inheriting from EventBase or StateBase is decorated with the [GenerateSerializer] attribute, so that serialization code is always generated correctly and missing attributes are caught at compile time.


Details & Requirements

  1. Analyzer Implementation

    • Use the Roslyn CompilationStartAction to register a syntax node action for ClassDeclarationSyntax.
    • For each class, use semantic analysis to check if its base type is EventBase or StateBase (directly or indirectly). :contentReference[oaicite:0]{index=0}
    • If such a class lacks the [GenerateSerializer] attribute, report a diagnostic with an error severity.
  2. Code Fix Provider

    • Provide a code-fix that adds the [GenerateSerializer] attribute to the class declaration when the diagnostic is triggered.
    • Ensure the fix respects existing using directives or adds using Orleans.CodeGeneration; as needed.
  3. Configuration & Suppression

    • Allow users to suppress the diagnostic via #pragma or EditorConfig settings if there are valid exceptions.
    • Expose a rule ID (e.g., AGENT001) and description in the analyzer’s descriptor for easy configuration.
  4. Testing & Integration

    • Create unit tests using the Roslyn test framework to verify detection on classes inheriting from EventBase/StateBase with and without the attribute.
    • Include integration tests to ensure the analyzer and code-fix work in real projects under the CI pipeline.
  5. Documentation & Adoption

    • Document how to install and enable the analyzer in project files (e.g., via NuGet).
    • Provide examples of classes that will pass or fail the check, and guide on how to apply the code fix.

Acceptance Criteria

  • The analyzer reports an error for each class deriving from EventBase or StateBase that does not have [GenerateSerializer].
  • The provided code fix correctly adds the attribute and required using directive.
  • Tests cover direct and indirect inheritance scenarios, as well as suppression cases.
  • Documentation is available detailing rule ID, configuration options, and usage examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions