diff --git a/KitX Script/Kscript.CSharp.Compiler/Examples/EndToEndTest.cs b/KitX Script/Kscript.CSharp.Compiler/Examples/EndToEndTest.cs
new file mode 100644
index 0000000..1cc63e8
--- /dev/null
+++ b/KitX Script/Kscript.CSharp.Compiler/Examples/EndToEndTest.cs
@@ -0,0 +1,392 @@
+using Kscript.CSharp.Parser;
+using Kscript.CSharp.Parser.Core;
+using Kscript.CSharp.Compiler;
+using Kscript.CSharp.Parser.Models;
+using KitX.Shared.CSharp.Plugin;
+using System.Reflection;
+
+namespace Kscript.CSharp.Compiler.Examples;
+
+///
+/// 端到端测试:用户脚本 → Compiler → Parser → PluginManager调用
+/// 验证完整的调用链是否正常工作
+///
+public static class EndToEndTest
+{
+ ///
+ /// 运行端到端测试
+ ///
+ public static async Task RunTest()
+ {
+ Console.WriteLine("=== KitX.CSharp.Compiler 端到端测试 ===\n");
+
+ try
+ {
+ // 1. 初始化插件管理器
+ Console.WriteLine("1. 初始化插件管理器...");
+ Parser.Parser.SetPluginManager(new MockPluginManager());
+
+ // 2. 创建测试插件清单
+ Console.WriteLine("2. 创建测试插件清单...");
+ var plugins = CreateTestPlugins();
+
+ // 3. 生成动态程序集
+ Console.WriteLine("3. 生成动态程序集...");
+ var assembly = Parser.Parser.Generate(plugins, "EndToEndTestAssembly");
+ Console.WriteLine($" ✓ 成功生成程序集: {assembly.FullName}");
+
+ // 4. 验证生成的程序集
+ Console.WriteLine("\n4. 验证生成的程序集...");
+ await ValidateGeneratedAssembly(assembly);
+
+ // 5. 创建脚本执行器并测试
+ Console.WriteLine("\n5. 创建脚本执行器并测试...");
+ await TestScriptExecution(assembly);
+
+ // 6. 测试错误处理
+ Console.WriteLine("\n6. 测试错误处理...");
+ await TestErrorHandling(assembly);
+
+ // 7. 性能测试
+ Console.WriteLine("\n7. 性能测试...");
+ await PerformanceTest(assembly);
+
+ Console.WriteLine("\n=== 端到端测试完成 ===");
+ Console.WriteLine("✅ 所有测试通过,C#脚本可以成功调用生成的插件方法!");
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"❌ 端到端测试失败: {ex.Message}");
+ Console.WriteLine($"详细错误信息:\n{ex}");
+ }
+ }
+
+ ///
+ /// 创建测试插件数据
+ ///
+ /// 插件信息列表
+ private static List CreateTestPlugins()
+ {
+ return new List
+ {
+ new PluginInfo
+ {
+ Name = "SampleCalculator",
+ Version = "1.0.0",
+ Functions = new List
+ {
+ new Function
+ {
+ Name = "Add",
+ ReturnValueType = "int",
+ Parameters = new List
+ {
+ new Parameter { Name = "a", Type = "int", IsOptional = false },
+ new Parameter { Name = "b", Type = "int", IsOptional = false }
+ }
+ },
+ new Function
+ {
+ Name = "Multiply",
+ ReturnValueType = "double",
+ Parameters = new List
+ {
+ new Parameter { Name = "x", Type = "double", IsOptional = false },
+ new Parameter { Name = "y", Type = "double", IsOptional = false }
+ }
+ },
+ new Function
+ {
+ Name = "Divide",
+ ReturnValueType = "double",
+ Parameters = new List
+ {
+ new Parameter { Name = "numerator", Type = "double", IsOptional = false },
+ new Parameter { Name = "denominator", Type = "double", IsOptional = false },
+ new Parameter { Name = "decimals", Type = "int", IsOptional = true, Value = "2" }
+ }
+ }
+ }
+ },
+ new PluginInfo
+ {
+ Name = "StringToolkit",
+ Version = "1.0.0",
+ Functions = new List
+ {
+ new Function
+ {
+ Name = "Reverse",
+ ReturnValueType = "string",
+ Parameters = new List
+ {
+ new Parameter { Name = "text", Type = "string", IsOptional = false }
+ }
+ },
+ new Function
+ {
+ Name = "Concat",
+ ReturnValueType = "string",
+ Parameters = new List
+ {
+ new Parameter { Name = "str1", Type = "string", IsOptional = false },
+ new Parameter { Name = "str2", Type = "string", IsOptional = false }
+ }
+ }
+ }
+ },
+ new PluginInfo
+ {
+ Name = "KitXWF",
+ Version = "1.0.0",
+ Functions = new List
+ {
+ new Function
+ {
+ Name = "Print",
+ ReturnValueType = "void",
+ Parameters = new List
+ {
+ new Parameter { Name = "message", Type = "string", IsOptional = false }
+ }
+ }
+ }
+ }
+ };
+ }
+
+ ///
+ /// 验证生成的程序集
+ ///
+ /// 生成的程序集
+ private static async Task ValidateGeneratedAssembly(Assembly assembly)
+ {
+ Console.WriteLine(" 验证程序集结构...");
+
+ // 获取所有插件类型
+ var types = Parser.Parser.GetPluginTypes(assembly);
+ Console.WriteLine($" 发现 {types.Count} 个插件类型:");
+
+ foreach (var type in types)
+ {
+ Console.WriteLine($" - {type.Name}");
+
+ // 获取所有方法
+ var methods = Parser.Parser.GetPluginMethods(type);
+ Console.WriteLine($" 包含 {methods.Count} 个方法:");
+
+ foreach (var method in methods)
+ {
+ var parameters = method.GetParameters();
+ var paramList = string.Join(", ", parameters.Select(p => $"{p.ParameterType.Name} {p.Name}"));
+ Console.WriteLine($" - {method.ReturnType.Name} {method.Name}({paramList})");
+ }
+ }
+
+ Console.WriteLine(" ✓ 程序集结构验证完成");
+ }
+
+ ///
+ /// 测试脚本执行
+ ///
+ /// 生成的程序集
+ private static async Task TestScriptExecution(Assembly assembly)
+ {
+ using var executor = new ScriptExecutor();
+
+ // 添加程序集引用
+ executor.AddAssemblyReference(assembly);
+ Console.WriteLine(" ✓ 已添加程序集引用到脚本执行器");
+
+ // 测试基本计算脚本
+ Console.WriteLine("\n 测试基本计算脚本...");
+ string basicScript = @"
+ // 测试加法
+ var sum = SampleCalculator.Add(10, 20);
+ KitXWF.Print(string.Format(""加法结果: {0}"", sum));
+
+ // 测试乘法
+ var product = SampleCalculator.Multiply(3.5, 2.8);
+ KitXWF.Print(string.Format(""乘法结果: {0}"", product));
+
+ // 测试字符串反转
+ var reversed = StringToolkit.Reverse(""Hello KitX"");
+ KitXWF.Print(string.Format(""字符串反转结果: {0}"", reversed));
+
+ return new { Sum = sum, Product = product, Reversed = reversed };
+ ";
+
+ var basicResult = await executor.ExecuteAsync(basicScript, "BasicTest");
+ Console.WriteLine($" ✓ 基本脚本执行成功: Sum={basicResult.Sum}, Product={basicResult.Product}, Reversed={basicResult.Reversed}");
+
+ // 测试复杂业务逻辑脚本
+ Console.WriteLine("\n 测试复杂业务逻辑脚本...");
+ string complexScript = @"
+ // 模拟订单处理
+ var orderItems = new[]
+ {
+ new { Name = ""商品A"", Price = 10.5, Quantity = 2 },
+ new { Name = ""商品B"", Price = 25.0, Quantity = 1 },
+ new { Name = ""商品C"", Price = 5.75, Quantity = 3 }
+ };
+
+ var totalAmount = 0.0;
+ var itemCount = orderItems.Length;
+
+ foreach (var item in orderItems)
+ {
+ var itemTotal = SampleCalculator.Multiply(item.Price, (double)item.Quantity);
+ totalAmount = totalAmount + itemTotal;
+ KitXWF.Print(string.Format(""处理商品: {0}, 小计: {1}"", item.Name, itemTotal));
+ }
+
+ // 计算平均价格
+ var averagePrice = SampleCalculator.Divide(totalAmount, (double)itemCount, 2);
+
+ // 生成订单摘要
+ var summary = StringToolkit.Concat(string.Format(""订单总额: {0}, 平均价格: {1}"", totalAmount, averagePrice), "" (已处理)"");
+
+ return new {
+ TotalAmount = totalAmount,
+ ItemCount = itemCount,
+ AveragePrice = averagePrice,
+ Summary = summary
+ };
+ ";
+
+ var complexResult = await executor.ExecuteAsync(complexScript, "ComplexTest");
+ Console.WriteLine($" ✓ 复杂脚本执行成功: Total={complexResult.TotalAmount}, Items={complexResult.ItemCount}, Avg={complexResult.AveragePrice}");
+
+ // 测试脚本验证功能
+ Console.WriteLine("\n 测试脚本验证功能...");
+ var validScript = "var x = 10; return x * 2;";
+ var invalidScript = "var x = 10; return x *; // 语法错误";
+
+ var validValidation = executor.ValidateScript(validScript);
+ var invalidValidation = executor.ValidateScript(invalidScript);
+
+ Console.WriteLine($" ✓ 有效脚本验证: {validValidation.IsValid} - {validValidation.Message}");
+ Console.WriteLine($" ✓ 无效脚本验证: {!invalidValidation.IsValid} - {invalidValidation.Message}");
+
+ // 显示执行器状态
+ var status = executor.GetStatus();
+ Console.WriteLine($" 执行器状态: {status.ReferencedAssembliesCount} 个程序集, {status.GlobalVariablesCount} 个全局变量");
+ }
+
+ ///
+ /// 测试错误处理
+ ///
+ /// 生成的程序集
+ private static async Task TestErrorHandling(Assembly assembly)
+ {
+ using var executor = new ScriptExecutor();
+ executor.AddAssemblyReference(assembly);
+
+ // 测试编译错误
+ Console.WriteLine(" 测试编译错误处理...");
+ try
+ {
+ var syntaxErrorScript = "var x = 10; var y = ; return x + y;"; // 故意语法错误
+ await executor.ExecuteAsync