Skip to content

Ship a Roslyn analyzer that nudges users toward StrongTypes.EFCore #17

@KaliCZ

Description

@KaliCZ

Context

Follow-up to #16. Once the EF Core bits live in a separate Kalicz.StrongTypes.EFCore package, the only friction left for users is knowing the package exists.

VS/Rider's built-in "unresolved symbol → install NuGet package" code fix already handles the case where a user types UseStrongTypes() without a reference — so nothing special is needed there.

What the IDE can't do on its own is proactively tell a user "you've declared a NonEmptyString column on an EF Core entity but you haven't installed the converter package." For that we'd ship a Roslyn analyzer inside the core Kalicz.StrongTypes package.

Proposal

Add a src/StrongTypes.Analyzers/ project (netstandard2.0, references Microsoft.CodeAnalysis.CSharp.Workspaces) packed into Kalicz.StrongTypes under analyzers/dotnet/cs/.

The analyzer emits a diagnostic when it sees a strong type used as an EF Core mapped property (e.g. on a class whose DbSet lives in a DbContext) without the StrongTypes.EFCore assembly referenced. The accompanying code fix adds the package reference.

Precedent: Microsoft.Extensions.Logging.Abstractions, System.Text.Json source-generator diagnostics, Microsoft.AspNetCore.Mvc.Api.Analyzers.

Why not now

The analyzer only becomes useful after #16 — there's no package to suggest installing today. And analyzer development has its own footprint (release versioning, suppression story, false-positive management) that deserves its own decision.

Done when

  • StrongTypes.Analyzers project ships inside Kalicz.StrongTypes as an analyzer.
  • Diagnostic fires on NonEmptyString (and future strong-type) EF Core mapped properties when StrongTypes.EFCore isn't referenced.
  • Code fix installs the package.
  • Suppression path documented for users who intentionally persist via another mechanism.

Depends on #16.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions