Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,26 @@ public static void Main(string[] args)
}";
const string expectedResult = @"class Program
{
public: static void Main(std::string args[])
public:
void Main(std::vector<std::string> args)
{
printf(""Hello, world!\n"");
}
};";
};

int main(int argc, char* argv[])
{
Program program{};
try
{
program.Main(std::vector<std::string>(argv + 1, argv + argc));
}
catch(...)
{
// Handle exception
}
return 0;
}";
var transformer = new CSharpToCppTransformer();
var actualResult = transformer.Transform(helloWorldCode);
Assert.Equal(expectedResult, actualResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ public class CSharpToCppTransformer : TextTransformer
// AppDomain.CurrentDomain.ProcessExit -= OnProcessExit;
// /* No translation. It is not possible to unsubscribe from std::atexit. */
(new Regex(@"AppDomain\.CurrentDomain\.ProcessExit -= ([a-zA-Z_][a-zA-Z0-9_]*);"), "/* No translation. It is not possible to unsubscribe from std::atexit. */", 0),
// class Program { ... public: static void Main(std::string args[]) ... };
// class Program { ... public: void Main(std::vector<std::string> args) ... }; \n\nint main(int argc, char* argv[]) { ... }
(new Regex(@"(?<before>class Program\s*\{(?:(?!\}\;).|\n)*?)public:\s*static\s+void\s+Main\(std::string\s+args\[\]\)(?<after>(?:(?!\}\;).|\n)*\}\;)"), "${before}public:" + Environment.NewLine + " void Main(std::vector<std::string> args)${after}" + Environment.NewLine + Environment.NewLine + "int main(int argc, char* argv[])" + Environment.NewLine + "{" + Environment.NewLine + " Program program{};" + Environment.NewLine + " try" + Environment.NewLine + " {" + Environment.NewLine + " program.Main(std::vector<std::string>(argv + 1, argv + argc));" + Environment.NewLine + " }" + Environment.NewLine + " catch(...)" + Environment.NewLine + " {" + Environment.NewLine + " // Handle exception" + Environment.NewLine + " }" + Environment.NewLine + " return 0;" + Environment.NewLine + "}", 0),
}.Cast<ISubstitutionRule>().ToList();

/// <summary>
Expand Down
Loading