Skip to content

Implement entire method generation (without prior partial declaration)#85

Draft
Copilot wants to merge 4 commits intofeature/metehod_templatefrom
copilot/implement-entire-method-generation
Draft

Implement entire method generation (without prior partial declaration)#85
Copilot wants to merge 4 commits intofeature/metehod_templatefrom
copilot/implement-entire-method-generation

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

Adds support for generating complete methods via Generate.Method() fluent API, where the method name, return type, parameters, and body are all specified in the generator — no partial method declaration required.

public partial class ColorsClassFluentCreated
{
    [MethodBodyGenerator("GetAllColorsString")]
    static IMethodBodyGenerator GetAllColorsString_Generator() =>
        Generate.Method()
            .WithName("GetAllColorsString")
            .WithReturnType<string>()
            .WithNoParameters()
            .BodyReturningConstant(() => string.Join(", ", Enum.GetNames<ColorsEnum>()));
}

// Generates:
// public string GetAllColorsString() { return "Red, Green, Blue"; }

Abstractions

  • Completed IMethodBuilderStage1Stage4 interfaces with terminal methods (BodyReturningConstant, BodyWithSwitchStatement, UseProvidedBody)
  • Added IGeneratorsFactory.StartFluentApiBuilderForMethod() and supporting IMethodBodyGeneratorStage0, IMethodBodyBuilder interfaces
  • Reverted switch body ForCases to params object[] and ReturnConstantValue to return IMethodBodyGeneratorSwitchBody (restoring chained ForCases support); removed intermediate CaseStage2

Generator pipeline

  • Made PartialMethod nullable in GeneratesMethodGenerationTarget; collector now allows missing partial methods for fluent patterns
  • Added GenerateFromEntireMethodPattern pipeline path and ExecuteEntireMethodGeneratorMethod runtime method
  • BuildDummyImplementation now scans for [MethodBodyGenerator] targets without partial methods and synthesizes dummy declarations (extracting signature from the fluent API syntax), so other generators' execution compilations don't fail

Recording factory

  • Added MethodRecord and recording implementations for all Method builder stages
  • RecordingGeneratorsFactory implements IGeneratorsFactory and captures method name, return type, parameter types, constant values, and switch body data

Examples & tests

  • Added ColorsClassFluentCreated (constant return, no params) and MapperFluentCreated (switch with enum mapping) examples
  • Added corresponding integration tests verifying runtime output and generated code shape
  • Updated existing tests for renamed interfaces (UseBodyUseProvidedBody, signature simplification)
Original prompt

This section details on the original issue you should resolve

<issue_title>Implement entire method generation</issue_title>
<issue_description>So far, only the body code generation has been implemented.
I've added some abstractions and examples to allow for entire method generation (without prior partial declaration).

Implement it.

Take a look at those examples. Don't modify them, just make sure they compile, add automated tests and implement them.

ColorsClassFluentCreated
MapperFluentCreated

For now forget about Method Template. Focus only on entire method generation (not only body).

The solutions needs to compile and tests need to pass after this PR. Examples should not be modified.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits March 11, 2026 20:23
…peline, and examples

Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
…st files

Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement entire method generation functionality Implement entire method generation (without prior partial declaration) Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants