PythonToCSharpConverter.cs:36 -- 移除未使用的 indentLevel 变量
Program.test.cs -- 将顶层语句改为 ManualTest.RunAsync() 方法,消除入口点冲突 BatchConversionService.cs:96 -- options 可空参数添加 ?? new ConversionOptions() 空值回退 Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
This commit is contained in:
@@ -2,10 +2,16 @@ using CodePlay.Core.Parsers;
|
|||||||
using CodePlay.Core.Converters;
|
using CodePlay.Core.Converters;
|
||||||
using CodePlay.Core.Common;
|
using CodePlay.Core.Common;
|
||||||
|
|
||||||
var parser = new CSharpParser();
|
namespace CodePlay.CLI.Tests;
|
||||||
var converter = new CSharpToJavaConverter();
|
|
||||||
|
|
||||||
var code = @"
|
public class ManualTest
|
||||||
|
{
|
||||||
|
public static async Task RunAsync()
|
||||||
|
{
|
||||||
|
var parser = new CSharpParser();
|
||||||
|
var converter = new CSharpToJavaConverter();
|
||||||
|
|
||||||
|
var code = @"
|
||||||
namespace Test
|
namespace Test
|
||||||
{
|
{
|
||||||
public class Model
|
public class Model
|
||||||
@@ -15,9 +21,11 @@ namespace Test
|
|||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
|
||||||
var tree = await parser.ParseAsync(code);
|
var tree = await parser.ParseAsync(code);
|
||||||
var result = await converter.ConvertAsync(tree, LanguageType.Java);
|
var result = await converter.ConvertAsync(tree, LanguageType.Java);
|
||||||
|
|
||||||
Console.WriteLine("Success: " + result.Success);
|
Console.WriteLine("Success: " + result.Success);
|
||||||
Console.WriteLine("=== Code ===");
|
Console.WriteLine("=== Code ===");
|
||||||
Console.WriteLine(result.TransformedCode ?? "NULL");
|
Console.WriteLine(result.TransformedCode ?? "NULL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public class PythonToCSharpConverter : IConverter
|
|||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
|
|
||||||
var lines = pythonCode.Split('\n');
|
var lines = pythonCode.Split('\n');
|
||||||
var indentLevel = 0;
|
|
||||||
|
|
||||||
foreach (var line in lines)
|
foreach (var line in lines)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class BatchConversionService : IBatchConversionService
|
|||||||
|
|
||||||
var sourceCode = await File.ReadAllTextAsync(sourceFile, cancellationToken);
|
var sourceCode = await File.ReadAllTextAsync(sourceFile, cancellationToken);
|
||||||
var conversionResult = await _conversionService.ConvertAsync(
|
var conversionResult = await _conversionService.ConvertAsync(
|
||||||
sourceCode, sourceLanguage.ToName(), targetLanguage.ToName(), options);
|
sourceCode, sourceLanguage.ToName(), targetLanguage.ToName(), options ?? new ConversionOptions());
|
||||||
|
|
||||||
if (conversionResult.Success)
|
if (conversionResult.Success)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user