Skip to content

Dummies: Define and document the contract of implicit generator conversions #190

Description

@Reefact

Problem

Concrete Dummies generators implicitly convert to their generated value type, which makes explicitly typed assignments concise:

string reference = Any.String().StartingWith("ORD-");

The same syntax is misleading in other C# contexts:

var reference = Any.String().StartingWith("ORD-"); // AnyString, not string

Calls through object, generic APIs or competing overloads can also box or pass the generator instead of triggering the conversion. The test suite already has to use explicitly typed locals around string.Join(params object[]) for this reason.

Impact

Users can accidentally retain a mutable-looking recipe where they expected a materialized value, generate more than once, or observe a generator's ToString() output in APIs accepting object. These failures are surprising because the implicit conversion makes generator and generated value appear interchangeable only in some language contexts.

Direction

Make the intended contract explicit before the public API stabilizes.

The preferred direction is to keep implicit conversions as assignment convenience while documenting .Generate() as the canonical, unambiguous materialization operation. The documentation should explain where conversions do and do not run and provide guidance for var, object, generic methods, collections and overload resolution.

An analyzer may be considered separately, but is not required by this issue.

Acceptance criteria

  • The public documentation states whether implicit conversions are a stable part of the API.
  • .Generate() is presented as the canonical form whenever the target type is not explicit.
  • Documentation includes examples for explicitly typed assignment, var, object/boxing and generic APIs.
  • Tests preserve the chosen behavior and cover the most misleading compiler-resolution cases.
  • The decision is recorded before a stable 1.0 API is published.

Context

Surfaced during a focused review of the standalone Dummies library.

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