From 5a5d93e603543dc3226325c94bd9d8338280a6ec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Mar 2026 13:15:52 +0000 Subject: [PATCH 1/3] Initial plan From 8f9d89d40651ed3975a25cc5431516399e674fff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Mar 2026 13:20:21 +0000 Subject: [PATCH 2/3] Fix simple generator invocation for parameterized methods Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com> --- .../GeneratesMethodExecutionRuntimeTests.cs | 27 ++++++++++++++ .../GeneratesMethodExecutionRuntime.cs | 36 +++++++++++++++++-- .../SimpleMethodWithParameter.cs | 4 +-- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/EasySourceGenerators.GeneratorTests/GeneratesMethodExecutionRuntimeTests.cs b/EasySourceGenerators.GeneratorTests/GeneratesMethodExecutionRuntimeTests.cs index 2da4545..701d7a1 100644 --- a/EasySourceGenerators.GeneratorTests/GeneratesMethodExecutionRuntimeTests.cs +++ b/EasySourceGenerators.GeneratorTests/GeneratesMethodExecutionRuntimeTests.cs @@ -90,6 +90,33 @@ public static class GenHost Assert.That(result.value, Is.EqualTo("hello")); } + [Test] + public void ExecuteSimpleGeneratorMethod_ExecutesStaticMethodWithParametersUsingDefaultValues() + { + CSharpCompilation compilation = CreateCompilation(""" + namespace TestNamespace; + + public partial class Target + { + public partial int GetValue(int input); + } + + public static class GenHost + { + public static int Generate(int input) => input + 5; + } + """); + + IMethodSymbol generatorMethod = GetMethodSymbol(compilation, "TestNamespace.GenHost", "Generate"); + IMethodSymbol partialMethod = GetMethodSymbol(compilation, "TestNamespace.Target", "GetValue"); + + (string? value, string? error) result = + GeneratesMethodExecutionRuntime.ExecuteSimpleGeneratorMethod(generatorMethod, partialMethod, compilation); + + Assert.That(result.error, Is.Null); + Assert.That(result.value, Is.EqualTo("5")); + } + [Test] public void ExecuteGeneratorMethodWithArgs_ConvertsArgumentsToMethodParameterType() { diff --git a/EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs b/EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs index 8efb3fa..112ef86 100644 --- a/EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs +++ b/EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs @@ -273,13 +273,43 @@ internal static IReadOnlyList GetAllUnimplementedPartialMethods(C private static object?[]? ConvertArguments(object?[]? args, MethodInfo methodInfo) { - if (args == null || methodInfo.GetParameters().Length == 0) + ParameterInfo[] parameters = methodInfo.GetParameters(); + if (parameters.Length == 0) { return null; } - Type parameterType = methodInfo.GetParameters()[0].ParameterType; - return new[] { Convert.ChangeType(args[0], parameterType) }; + if (args != null && args.Length > parameters.Length) + { + throw new TargetParameterCountException(); + } + + object?[] convertedArguments = new object?[parameters.Length]; + for (int i = 0; i < parameters.Length; i++) + { + ParameterInfo parameter = parameters[i]; + object? argument = args != null && i < args.Length ? args[i] : null; + if (argument == null) + { + convertedArguments[i] = GetDefaultValue(parameter.ParameterType); + continue; + } + + Type targetType = Nullable.GetUnderlyingType(parameter.ParameterType) ?? parameter.ParameterType; + convertedArguments[i] = Convert.ChangeType(argument, targetType); + } + + return convertedArguments; + } + + private static object? GetDefaultValue(Type type) + { + if (!type.IsValueType || Nullable.GetUnderlyingType(type) != null) + { + return null; + } + + return Activator.CreateInstance(type); } private static SwitchBodyData ExtractSwitchBodyData(object lastRecord, ITypeSymbol returnType) diff --git a/EasySourceGenerators.Tests/SimpleMethodWithParameter.cs b/EasySourceGenerators.Tests/SimpleMethodWithParameter.cs index 526bfc6..2bca91e 100644 --- a/EasySourceGenerators.Tests/SimpleMethodWithParameter.cs +++ b/EasySourceGenerators.Tests/SimpleMethodWithParameter.cs @@ -23,7 +23,7 @@ namespace EasySourceGenerators.Tests; partial class SimpleMethodWithParameterClass { - public partial string SimpleMethodWithParameter() + public partial int SimpleMethodWithParameter(int someIntParameter) { return 5; } @@ -43,4 +43,4 @@ private static int SimpleMethodWithParameter_Generator(int someIntParameter) { return 5; } -} \ No newline at end of file +} From 739081dc48bfa4096d03cff4fb57a2d3b486fe69 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Mar 2026 13:23:17 +0000 Subject: [PATCH 3/3] Refine argument conversion loop variable naming Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com> --- .../GeneratesMethodExecutionRuntime.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs b/EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs index 112ef86..3d74c16 100644 --- a/EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs +++ b/EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs @@ -285,18 +285,18 @@ internal static IReadOnlyList GetAllUnimplementedPartialMethods(C } object?[] convertedArguments = new object?[parameters.Length]; - for (int i = 0; i < parameters.Length; i++) + for (int parameterIndex = 0; parameterIndex < parameters.Length; parameterIndex++) { - ParameterInfo parameter = parameters[i]; - object? argument = args != null && i < args.Length ? args[i] : null; + ParameterInfo parameter = parameters[parameterIndex]; + object? argument = args != null && parameterIndex < args.Length ? args[parameterIndex] : null; if (argument == null) { - convertedArguments[i] = GetDefaultValue(parameter.ParameterType); + convertedArguments[parameterIndex] = GetDefaultValue(parameter.ParameterType); continue; } Type targetType = Nullable.GetUnderlyingType(parameter.ParameterType) ?? parameter.ParameterType; - convertedArguments[i] = Convert.ChangeType(argument, targetType); + convertedArguments[parameterIndex] = Convert.ChangeType(argument, targetType); } return convertedArguments;