Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加 动态方法模板 扩展 #284

Merged
merged 1 commit into from
Apr 30, 2024
Merged

增加 动态方法模板 扩展 #284

merged 1 commit into from
Apr 30, 2024

Conversation

NMSAzulX
Copy link
Collaborator

@NMSAzulX NMSAzulX commented Apr 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced the ExtensionSample project to demonstrate dynamic function creation and execution.
    • Added new methods in StringExtension for dynamic method creation with various modifiers.
    • Introduced extension methods in SystemDelegateExtension for converting scripts to delegates.
  • Enhancements

    • Updated the Natasha CSharp compiler and extensions to support the latest .NET features like nullable reference types and implicit usings.
  • Bug Fixes

    • Corrected GitHub label naming in the workflow runner from "phasee-done" to "phase-done".
  • Refactor

    • Simplified object creation in TypeNameReverser using target-typed new() expressions.
    • Updated HashSet<Type> initialization to use more concise syntax in TypeNatashaExtension.

Copy link

coderabbitai bot commented Apr 30, 2024

Walkthrough

The update introduces new projects and enhances existing functionalities across the Natasha solution. It adds ExtensionSample and MethodCreator projects, updates project configurations, and refines method generation capabilities. Changes focus on modernizing code syntax, improving method creation flexibility, and ensuring version consistency across the solution.

Changes

File Path Change Summary
.github/project.yml, Natasha.sln, samples/.../ExtensionSample.csproj Added new projects: ExtensionSample and MethodCreator. Updated project configurations.
samples/.../Program.cs, src/.../StringExtension.cs, src/.../SystemDelegateExtension.cs Enhanced method creation capabilities and introduced new functionalities in program execution.
src/.../Natasha.CSharp.Compiler.csproj, src/.../TypeNameReverser.cs, src/.../TypeNatashaExtension.cs Updated version numbers and simplified code with modern C# syntax.
test/workflow/.../Runner.cs Minor label name correction in GitHub workflow configuration.

🐰✨
In the code garden, changes bloom,
New projects sprout, old versions groom.
With each commit, a new feature grows,
In Natasha's realm, where coding flows.
Hop along, let’s see what’s new,
In this digital meadow, crafted just for you!
🌟🐇


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a051dbb and be47e1b.
Files selected for processing (12)
  • .github/project.yml (2 hunks)
  • Natasha.sln (3 hunks)
  • samples/ExtensionSample/ExtensionSample.csproj (1 hunks)
  • samples/ExtensionSample/Program.cs (1 hunks)
  • samples/HotReloadSample/Program.cs (3 hunks)
  • src/Natasha.CSharp/Extension/Natasha.CSharp.Extension.MethodCreator/Natasha.CSharp.Extension.MethodCreator.csproj (1 hunks)
  • src/Natasha.CSharp/Extension/Natasha.CSharp.Extension.MethodCreator/StringExtension.cs (1 hunks)
  • src/Natasha.CSharp/Extension/Natasha.CSharp.Extension.MethodCreator/SystemDelegateExtension.cs (1 hunks)
  • src/Natasha.CSharp/Natasha.CSharp.Compiler/Natasha.CSharp.Compiler.csproj (1 hunks)
  • src/Natasha.CSharp/Natasha.CSharp.Compiler/Reverser/TypeNameReverser.cs (4 hunks)
  • src/Natasha.CSharp/Natasha.CSharp.Compiler/Reverser/TypeNatashaExtension.cs (1 hunks)
  • test/workflow/Workflow.Runner/Runner.cs (1 hunks)
Files skipped from review due to trivial changes (5)
  • Natasha.sln
  • src/Natasha.CSharp/Extension/Natasha.CSharp.Extension.MethodCreator/Natasha.CSharp.Extension.MethodCreator.csproj
  • src/Natasha.CSharp/Natasha.CSharp.Compiler/Natasha.CSharp.Compiler.csproj
  • src/Natasha.CSharp/Natasha.CSharp.Compiler/Reverser/TypeNameReverser.cs
  • test/workflow/Workflow.Runner/Runner.cs
Additional comments not posted (3)
samples/ExtensionSample/ExtensionSample.csproj (1)

3-8: Ensure that the target framework and settings are compatible with all dependencies.

samples/HotReloadSample/Program.cs (1)

Line range hint 27-176: Ensure comprehensive error handling and logging in the main method, especially around dynamic assembly operations.

Verification successful

The verification process has revealed that the Program.cs file does include error handling around dynamic assembly operations, specifically around the NewAssembly method call, as evidenced in the provided code snippet. However, the scripts executed did not return any results, likely due to limitations in the pattern used or script execution. Therefore, the initial review comment about ensuring comprehensive error handling and logging is consistent with the codebase.

  • Error handling is implemented around the NewAssembly method call with a try-catch block that catches exceptions, logs them, and handles them appropriately.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify comprehensive error handling and logging in `HotReloadSample/Program.cs`.

# Search for try-catch blocks and logging statements around dynamic operations.
ast-grep --lang csharp --pattern $'try { $$$ } catch($_) { $$$ }' samples/HotReloadSample/Program.cs

Length of output: 101



Script:

#!/bin/bash
# Description: Re-verify comprehensive error handling and logging in `HotReloadSample/Program.cs`.

# Search for try-catch blocks specifically around dynamic assembly operations.
ast-grep --lang csharp --pattern $'try { $$$ NewAssembly($$$); $$$ } catch($_) { $$$ }' samples/HotReloadSample/Program.cs

Length of output: 123

.github/project.yml (1)

Line range hint 91-101: Confirm that all project settings and dependencies are correctly configured and necessary.

Verification successful

The verification process confirms that the projects configuration in the .github/project.yml file is correctly set to an empty array (projects: []). This matches the provided snippet and indicates that the configuration is correct and necessary as per the current setup of the project.

  • The projects array is correctly configured as empty, which might be intentional depending on the project's workflow requirements.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify project settings and dependencies in `.github/project.yml`.

# Check for configuration issues in project settings.
ast-grep --lang yaml --pattern $'projects: { $$$ }' .github/project.yml

Length of output: 181



Script:

#!/bin/bash
# Description: Verify project settings and dependencies in `.github/project.yml` using ripgrep.

# Check for the presence and correctness of the 'projects' configuration.
rg 'projects:\s*\[\s*\]' .github/project.yml

Length of output: 83


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NMSAzulX
Copy link
Collaborator Author

未检测到合适的 ISSUE 推荐给您。感谢您的反馈!

该条自动推荐信息来自于 nms-bot.

@NMSAzulX NMSAzulX added pr_src 此次提交包含 [源码工程] 相关的改动. pr_action 此次提交包含 [Action] 相关的改动. labels Apr 30, 2024
@NMSAzulX
Copy link
Collaborator Author

@coderabbitai review

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Out of diff range and nitpick comments (1)
samples/ExtensionSample/Program.cs (1)

13-14: Consider removing Console.ReadKey() for production code to avoid unnecessary waits.

Comment on lines +7 to +13
NatashaManagement.RegistDomainCreator<NatashaDomainCreator>();

var func = "return arg1+arg2;"
.WithAssemblyBuilder(opt=>opt.AddReferenceAndUsingCode<object>())
.ToFunc<int, int, int>();

Console.WriteLine(func(1,2));
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

No try-catch blocks were found in samples/ExtensionSample/Program.cs around the dynamic operations. It is recommended to implement proper error handling and logging to ensure robustness, especially given the dynamic nature of the operations involved.

  • File: samples/ExtensionSample/Program.cs
  • Recommendation: Implement try-catch blocks around dynamic operations to handle potential errors and log them appropriately.
Analysis chain

Ensure proper error handling and logging for dynamic operations.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that error handling and logging are implemented for dynamic operations in `ExtensionSample/Program.cs`.

# Search for try-catch blocks around dynamic operations.
ast-grep --lang csharp --pattern $'try { $$$ } catch($_) { $$$ }' src/samples/ExtensionSample/Program.cs

Length of output: 191



Script:

#!/bin/bash
# Find the correct path for Program.cs in the ExtensionSample directory
fd Program.cs samples/ExtensionSample --exec echo "Found Program.cs at: {}"

Length of output: 133


Script:

#!/bin/bash
# Assuming the correct path is found, re-run the ast-grep command to check for try-catch blocks
ast-grep --lang csharp --pattern $'try { $$$ } catch($_) { $$$ }' samples/ExtensionSample/Program.cs

Length of output: 101

Comment on lines +11 to +12
<ProjectReference Include="..\..\src\Natasha.CSharp\Component\Core\Natasha.CSharp.Compiler.Domain\Natasha.CSharp.Compiler.Domain.csproj" />
<ProjectReference Include="..\..\src\Natasha.CSharp\Extension\Natasha.CSharp.Extension.MethodCreator\Natasha.CSharp.Extension.MethodCreator.csproj" />
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The verification process has revealed that the project references listed in the ExtensionSample.csproj file do not exist at the specified paths. This could potentially lead to build errors or issues with project dependencies. It is recommended to check the paths and ensure that the referenced projects are correctly located or updated in the project file.

  • ..\..\src\Natasha.CSharp\Component\Core\Natasha.CSharp.Compiler.Domain\Natasha.CSharp.Compiler.Domain.csproj does not exist.
  • ..\..\src\Natasha.CSharp\Extension\Natasha.CSharp.Extension.MethodCreator\Natasha.CSharp.Extension.MethodCreator.csproj does not exist.
Analysis chain

Confirm that all project references are correctly resolved and necessary for the project.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all project references in `ExtensionSample.csproj` are correctly resolved.

# List all project references and check their existence.
ast-grep --lang xml --pattern $'<ProjectReference Include="$$$" />' samples/ExtensionSample/ExtensionSample.csproj

Length of output: 222



Script:

#!/bin/bash
# Extract project references from the .csproj file and check their existence.

# Extract the paths of project references
grep '<ProjectReference Include=' samples/ExtensionSample/ExtensionSample.csproj | sed -e 's/.*Include="\([^"]*\)".*/\1/'

# Check if the extracted paths exist
paths=$(grep '<ProjectReference Include=' samples/ExtensionSample/ExtensionSample.csproj | sed -e 's/.*Include="\([^"]*\)".*/\1/')
for path in $paths; do
    if [ -f "$path" ]; then
        echo "$path exists."
    else
        echo "$path does not exist."
    fi
done

Length of output: 1558

Comment on lines +8 to +19
public static (string script, AssemblyCSharpBuilder builder) WithAssemblyBuilder(this string script, Func<AssemblyCSharpBuilder, AssemblyCSharpBuilder> config)
{
AssemblyCSharpBuilder builder = new();
config?.Invoke(builder);
return (script, builder);
}
public static (string script, AssemblyCSharpBuilder builder) WithAssemblyBuilder(this string script, Func<NatashaLoadContext, NatashaLoadContext> config)
{
AssemblyCSharpBuilder builder = new();
builder.ConfigLoadContext(config);
return (script, builder);
}
Copy link

Choose a reason for hiding this comment

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

Ensure that the WithAssemblyBuilder methods handle null configurations gracefully.

- config?.Invoke(builder);
+ if (config != null) {
+     config(builder);
+ } else {
+     // Handle null configuration appropriately
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
public static (string script, AssemblyCSharpBuilder builder) WithAssemblyBuilder(this string script, Func<AssemblyCSharpBuilder, AssemblyCSharpBuilder> config)
{
AssemblyCSharpBuilder builder = new();
config?.Invoke(builder);
return (script, builder);
}
public static (string script, AssemblyCSharpBuilder builder) WithAssemblyBuilder(this string script, Func<NatashaLoadContext, NatashaLoadContext> config)
{
AssemblyCSharpBuilder builder = new();
builder.ConfigLoadContext(config);
return (script, builder);
}
public static (string script, AssemblyCSharpBuilder builder) WithAssemblyBuilder(this string script, Func<AssemblyCSharpBuilder, AssemblyCSharpBuilder> config)
{
AssemblyCSharpBuilder builder = new();
if (config != null) {
config(builder);
} else {
// Handle null configuration appropriately
}
return (script, builder);
}
public static (string script, AssemblyCSharpBuilder builder) WithAssemblyBuilder(this string script, Func<NatashaLoadContext, NatashaLoadContext> config)
{
AssemblyCSharpBuilder builder = new();
builder.ConfigLoadContext(config);
return (script, builder);
}

Comment on lines +21 to +60
public static T? CreateMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo, string? modifier = null) where T: Delegate
{

var className = $"N{Guid.NewGuid():N}";
var methodInfo = typeof(T).GetMethod("Invoke")!;

var returnTypeScript = methodInfo.ReturnType.GetDevelopName();
var parameterScript = new StringBuilder();

var methodParameters = methodInfo.GetParameters();
for (int i = 0; i < methodParameters.Length; i+=1)
{
parameterScript.Append($"{methodParameters[i].ParameterType.GetDevelopName()} arg{i+1},");
}
if (parameterScript.Length > 0)
{
parameterScript.Length -= 1;
}

buildInfo.builder.Add($"public static class {className} {{ public static {(modifier ?? string.Empty)} {returnTypeScript} Invoke({parameterScript}){{ {buildInfo.script} }} }}");
var asm = buildInfo.builder.GetAssembly();
var type = asm.GetType(className);
if (type != null)
{
return (T)Delegate.CreateDelegate(typeof(T), type.GetMethod("Invoke")!);
}
return null;
}
public static T? CreateAsyncMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where T : Delegate
{
return CreateMethod<T>(buildInfo, "async");
}
public static T? CreateUnsafeMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where T : Delegate
{
return CreateMethod<T>(buildInfo, "unsafe");
}
public static T? CreateUnsafeAsyncMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where T : Delegate
{
return CreateMethod<T>(buildInfo, "unsafe async");
}
Copy link

Choose a reason for hiding this comment

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

Optimize string and delegate handling in CreateMethod to improve performance and reduce memory usage.

- var className = $"N{Guid.NewGuid():N}";
+ var className = $"N{Guid.NewGuid().ToString("N")}";
- for (int i = 0; i < methodParameters.Length; i+=1)
+ for (int i = 0; i < methodParameters.Length; i++)
- parameterScript.Append($"{methodParameters[i].ParameterType.GetDevelopName()} arg{i+1},");
+ parameterScript.Append(methodParameters[i].ParameterType.GetDevelopName()).Append(" arg").Append(i+1).Append(",");

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
public static T? CreateMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo, string? modifier = null) where T: Delegate
{
var className = $"N{Guid.NewGuid():N}";
var methodInfo = typeof(T).GetMethod("Invoke")!;
var returnTypeScript = methodInfo.ReturnType.GetDevelopName();
var parameterScript = new StringBuilder();
var methodParameters = methodInfo.GetParameters();
for (int i = 0; i < methodParameters.Length; i+=1)
{
parameterScript.Append($"{methodParameters[i].ParameterType.GetDevelopName()} arg{i+1},");
}
if (parameterScript.Length > 0)
{
parameterScript.Length -= 1;
}
buildInfo.builder.Add($"public static class {className} {{ public static {(modifier ?? string.Empty)} {returnTypeScript} Invoke({parameterScript}){{ {buildInfo.script} }} }}");
var asm = buildInfo.builder.GetAssembly();
var type = asm.GetType(className);
if (type != null)
{
return (T)Delegate.CreateDelegate(typeof(T), type.GetMethod("Invoke")!);
}
return null;
}
public static T? CreateAsyncMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where T : Delegate
{
return CreateMethod<T>(buildInfo, "async");
}
public static T? CreateUnsafeMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where T : Delegate
{
return CreateMethod<T>(buildInfo, "unsafe");
}
public static T? CreateUnsafeAsyncMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where T : Delegate
{
return CreateMethod<T>(buildInfo, "unsafe async");
}
public static T? CreateMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo, string? modifier = null) where T: Delegate
{
var className = $"N{Guid.NewGuid().ToString("N")}";
var methodInfo = typeof(T).GetMethod("Invoke")!;
var returnTypeScript = methodInfo.ReturnType.GetDevelopName();
var parameterScript = new StringBuilder();
var methodParameters = methodInfo.GetParameters();
for (int i = 0; i < methodParameters.Length; i++)
{
parameterScript.Append(methodParameters[i].ParameterType.GetDevelopName()).Append(" arg").Append(i+1).Append(",");
}
if (parameterScript.Length > 0)
{
parameterScript.Length -= 1;
}
buildInfo.builder.Add($"public static class {className} {{ public static {(modifier ?? string.Empty)} {returnTypeScript} Invoke({parameterScript}){{ {buildInfo.script} }} }}");
var asm = buildInfo.builder.GetAssembly();
var type = asm.GetType(className);
if (type != null)
{
return (T)Delegate.CreateDelegate(typeof(T), type.GetMethod("Invoke")!);
}
return null;
}
public static T? CreateAsyncMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where T : Delegate
{
return CreateMethod<T>(buildInfo, "async");
}
public static T? CreateUnsafeMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where T : Delegate
{
return CreateMethod<T>(buildInfo, "unsafe");
}
public static T? CreateUnsafeAsyncMethod<T>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where T : Delegate
{
return CreateMethod<T>(buildInfo, "unsafe async");
}

@@ -47,7 +47,7 @@ public static bool IsImplementFrom<T>(this Type type)

public static HashSet<Type> GetAllTypes(this Type type)
{
HashSet<Type> result = new();
HashSet<Type> result = [];
Copy link

Choose a reason for hiding this comment

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

Correct the syntax error in initializing HashSet<Type> with empty brackets.

- HashSet<Type> result = [];
+ HashSet<Type> result = new HashSet<Type>();

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
HashSet<Type> result = [];
HashSet<Type> result = new HashSet<Type>();

Comment on lines +7 to +106
public static Action<T1>? ToAction<T1>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1>>();
}
public static Action<T1, T2>? ToAction<T1, T2>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2>>();
}
public static Action<T1, T2, T3>? ToAction<T1, T2, T3>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3>>();
}
public static Action<T1, T2, T3, T4>? ToAction<T1, T2, T3, T4>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4>>();
}
public static Action<T1, T2, T3, T4, T5>? ToAction<T1, T2, T3, T4, T5>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5>>();
}
public static Action<T1, T2, T3, T4, T5, T6>? ToAction<T1, T2, T3, T4, T5, T6>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7>? ToAction<T1, T2, T3, T4, T5, T6, T7>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>>();
}
#endregion


#region Func Delegate
public static Func<T1>? ToFunc<T1>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1>>();
}
public static Func<T1, T2>? ToFunc<T1, T2>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2>>();
}
public static Func<T1, T2, T3>? ToFunc<T1, T2, T3>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3>>();
}
public static Func<T1, T2, T3, T4>? ToFunc<T1, T2, T3, T4>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4>>();
}
public static Func<T1, T2, T3, T4, T5>? ToFunc<T1, T2, T3, T4, T5>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5>>();
}
public static Func<T1, T2, T3, T4, T5, T6>? ToFunc<T1, T2, T3, T4, T5, T6>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7>? ToFunc<T1, T2, T3, T4, T5, T6, T7>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>>();
}
Copy link

Choose a reason for hiding this comment

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

Consider refactoring to reduce code duplication in delegate conversion methods.

- public static Action<T1>? ToAction<T1>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
- {
-     return buildInfo.CreateMethod<Action<T1>>();
- }
- public static Action<T1, T2>? ToAction<T1, T2>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
- {
-     return buildInfo.CreateMethod<Action<T1, T2>>();
- }
+ // Example refactoring for two methods, apply similarly to others
+ public static TDelegate? ToDelegate<TDelegate>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where TDelegate : Delegate
+ {
+     return buildInfo.CreateMethod<TDelegate>();
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
public static Action<T1>? ToAction<T1>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1>>();
}
public static Action<T1, T2>? ToAction<T1, T2>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2>>();
}
public static Action<T1, T2, T3>? ToAction<T1, T2, T3>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3>>();
}
public static Action<T1, T2, T3, T4>? ToAction<T1, T2, T3, T4>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4>>();
}
public static Action<T1, T2, T3, T4, T5>? ToAction<T1, T2, T3, T4, T5>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5>>();
}
public static Action<T1, T2, T3, T4, T5, T6>? ToAction<T1, T2, T3, T4, T5, T6>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7>? ToAction<T1, T2, T3, T4, T5, T6, T7>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>>();
}
#endregion
#region Func Delegate
public static Func<T1>? ToFunc<T1>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1>>();
}
public static Func<T1, T2>? ToFunc<T1, T2>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2>>();
}
public static Func<T1, T2, T3>? ToFunc<T1, T2, T3>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3>>();
}
public static Func<T1, T2, T3, T4>? ToFunc<T1, T2, T3, T4>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4>>();
}
public static Func<T1, T2, T3, T4, T5>? ToFunc<T1, T2, T3, T4, T5>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5>>();
}
public static Func<T1, T2, T3, T4, T5, T6>? ToFunc<T1, T2, T3, T4, T5, T6>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7>? ToFunc<T1, T2, T3, T4, T5, T6, T7>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>>();
}
public static TDelegate? ToDelegate<TDelegate>(in this (string script, AssemblyCSharpBuilder builder) buildInfo) where TDelegate : Delegate
{
return buildInfo.CreateMethod<TDelegate>();
}
public static Action<T1, T2, T3>? ToAction<T1, T2, T3>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3>>();
}
public static Action<T1, T2, T3, T4>? ToAction<T1, T2, T3, T4>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4>>();
}
public static Action<T1, T2, T3, T4, T5>? ToAction<T1, T2, T3, T4, T5>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5>>();
}
public static Action<T1, T2, T3, T4, T5, T6>? ToAction<T1, T2, T3, T4, T5, T6>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7>? ToAction<T1, T2, T3, T4, T5, T6, T7>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>>();
}
public static Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>? ToAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>>();
}
#endregion
#region Func Delegate
public static Func<T1>? ToFunc<T1>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1>>();
}
public static Func<T1, T2>? ToFunc<T1, T2>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2>>();
}
public static Func<T1, T2, T3>? ToFunc<T1, T2, T3>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3>>();
}
public static Func<T1, T2, T3, T4>? ToFunc<T1, T2, T3, T4>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4>>();
}
public static Func<T1, T2, T3, T4, T5>? ToFunc<T1, T2, T3, T4, T5>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5>>();
}
public static Func<T1, T2, T3, T4, T5, T6>? ToFunc<T1, T2, T3, T4, T5, T6>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7>? ToFunc<T1, T2, T3, T4, T5, T6, T7>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>>();
}
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>? ToFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(in this (string script, AssemblyCSharpBuilder builder) buildInfo)
{
return buildInfo.CreateMethod<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>>();
}

@NMSAzulX NMSAzulX merged commit 9373db1 into dev.next Apr 30, 2024
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr_action 此次提交包含 [Action] 相关的改动. pr_src 此次提交包含 [源码工程] 相关的改动.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

1 participant