Skip to content

Fix modifier of the generated options builder object.#53

Merged
lindexi merged 1 commit intomainfrom
t/lvyi/modifier
Jul 7, 2025
Merged

Fix modifier of the generated options builder object.#53
lindexi merged 1 commit intomainfrom
t/lvyi/modifier

Conversation

@walterlv
Copy link
Member

@walterlv walterlv commented Jul 7, 2025

Fix #50

@CLAassistant
Copy link

CLAassistant commented Jul 7, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that the generated builder class visibility matches the accessibility of the source command object.

  • Capture the public accessibility flag in the command model
  • Add a corresponding IsPublic property to the model record
  • Update the builder generator template to emit public or internal accordingly

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/DotNetCampus.CommandLine.Analyzer/Generators/ModelProviding/CommandModelProvider.cs Compute isPublic flag and pass it into CommandObjectGeneratingModel
src/DotNetCampus.CommandLine.Analyzer/Generators/ModelProviding/CommandModelProvider.cs Add IsPublic property to the model record
src/DotNetCampus.CommandLine.Analyzer/Generators/BuilderGenerator.cs Use model.IsPublic to choose public vs. internal in class modifier
Comments suppressed due to low confidence (2)

src/DotNetCampus.CommandLine.Analyzer/Generators/ModelProviding/CommandModelProvider.cs:137

  • Add an XML doc comment for the IsPublic property to explain that it controls the visibility modifier of the generated builder class.
    public required bool IsPublic { get; init; }

src/DotNetCampus.CommandLine.Analyzer/Generators/BuilderGenerator.cs:78

  • Add unit tests that verify builder code is generated with public when the command object is public and internal otherwise.
{{(model.IsPublic ? "public" : "internal")}} sealed class {{model.GetBuilderTypeName()}}

@lindexi
Copy link
Member

lindexi commented Jul 7, 2025

修不了 #51 的问题,我重新调查发现,这是由于没有生成 OptionsBuilder 导致的。只要 Options 没有任何标记,则 OptionsBuilder 不会生成

// Options.cs

namespace HalnerefaiwhoLanallwaynai;

public class Options
{
    public required string Name { get; init; }
}

@lindexi lindexi merged commit d13aa06 into main Jul 7, 2025
3 checks passed
@lindexi lindexi deleted the t/lvyi/modifier branch July 7, 2025 03:30
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.

Option 定义在 A 程序集,则在 B 程序集不能使用到此类型

3 participants