Adds a script processor for super flexible text generation
This commit is contained in:
parent
e8339e4955
commit
0edc8104c9
84 changed files with 438 additions and 6 deletions
45
source/SnapWrap/SnapWrap.cs
Normal file
45
source/SnapWrap/SnapWrap.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Scripting;
|
||||
using Microsoft.CodeAnalysis.Scripting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnapWrap
|
||||
{
|
||||
public class SnapWrap
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string input = args[0];
|
||||
string output = args[1];
|
||||
|
||||
try
|
||||
{
|
||||
var inputCode = File.ReadAllText(input);
|
||||
|
||||
|
||||
var options = ScriptOptions.Default
|
||||
.WithReferences(AppDomain.CurrentDomain.GetAssemblies()) // Add necessary assemblies
|
||||
.WithImports("System");
|
||||
|
||||
using (var sw = new StreamWriter(output))
|
||||
{
|
||||
Console.SetOut(sw); // Redirect console output
|
||||
var scriptState = CSharpScript.RunAsync(inputCode, options).Result;
|
||||
|
||||
// Reset console output
|
||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()));
|
||||
|
||||
Console.WriteLine("Output file generated successfully.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"ERROR: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue