-
Notifications
You must be signed in to change notification settings - Fork 224
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
增加 动态方法模板 扩展 #284
Conversation
WalkthroughThe update introduces new projects and enhances existing functionalities across the Natasha solution. It adds Changes
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (12)
Files skipped from review due to trivial changes (5)
Additional comments not posted (3)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
未检测到合适的 ISSUE 推荐给您。感谢您的反馈!
|
@coderabbitai review |
There was a problem hiding this 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 removingConsole.ReadKey()
for production code to avoid unnecessary waits.
NatashaManagement.RegistDomainCreator<NatashaDomainCreator>(); | ||
|
||
var func = "return arg1+arg2;" | ||
.WithAssemblyBuilder(opt=>opt.AddReferenceAndUsingCode<object>()) | ||
.ToFunc<int, int, int>(); | ||
|
||
Console.WriteLine(func(1,2)); |
There was a problem hiding this comment.
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
<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" /> |
There was a problem hiding this comment.
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
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); | ||
} |
There was a problem hiding this comment.
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.
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); | |
} |
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"); | ||
} |
There was a problem hiding this comment.
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.
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 = []; |
There was a problem hiding this comment.
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.
HashSet<Type> result = []; | |
HashSet<Type> result = new HashSet<Type>(); |
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>>(); | ||
} |
There was a problem hiding this comment.
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.
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>>(); | |
} |
Summary by CodeRabbit
New Features
ExtensionSample
project to demonstrate dynamic function creation and execution.StringExtension
for dynamic method creation with various modifiers.SystemDelegateExtension
for converting scripts to delegates.Enhancements
Bug Fixes
Refactor
TypeNameReverser
using target-typednew()
expressions.HashSet<Type>
initialization to use more concise syntax inTypeNatashaExtension
.