Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the command line handling architecture to eliminate delegates and optimize memory allocation. The changes also improve parsing performance as a side effect. The core change replaces the delegate-based CommandObjectFactory pattern with an interface-based ICommandObjectMetadata approach that encapsulates both object creation and execution logic.
- Replaced delegate-based command handling with interface-based metadata classes
- Consolidated command object creation and execution logic into structured metadata types
- Removed delegate parameters from parser constructors in favor of direct method calls
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
CommandLineParser.cs |
Replaced delegate callbacks with direct method calls to ICommandObjectBuilder interface |
TaskCommandHandler.cs |
Refactored anonymous handler classes to use metadata pattern instead of delegates |
ICommandRunnerBuilder.cs |
Updated method signatures to use ICommandObjectMetadata instead of CommandObjectFactory |
ICommandHandler.cs |
Renamed ICommandOptions to ICommandObject and added backward compatibility |
ICommandObjectMetadata.cs |
Added new interface definitions for metadata-based command object handling |
CommandRunningContext.cs |
Moved CommandRunningContext to separate file from CommandObjectFactory.cs |
CommandObjectFactory.cs |
Removed file containing delegate definitions |
CommandRunnerBuilderExtensions.cs |
Updated extension methods to use metadata pattern |
CommandRunner.cs |
Refactored internal storage and execution to use metadata instead of delegates |
CommandLineExceptionHandler.cs |
Added metadata wrapper for exception handlers |
CommandLine.cs |
Removed deprecated As method overload |
ModelBuilderGenerator.cs |
Updated source generator to create metadata classes instead of static factory methods |
InterceptorGenerator.cs |
Updated interceptor generation to instantiate metadata objects |
AddHandlers.cs |
Added performance test for handler addition |
CommandLineArguments.cs |
Added test data for performance benchmarks |
Program.cs |
Updated sample code to use new metadata pattern |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
lindexi
approved these changes
Sep 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
对于两次 AddHandler 删除委托后的优化效果:
上:本次 PR 之前
下:本次 PR 之后
可以看到,耗时减少了,分配也较少了。