ConsoleWriter.cs 618 B

1234567891011121314151617181920
  1. using System.IO;
  2. using System.Reflection;
  3. using System.Text;
  4. using HarmonyLib;
  5. namespace BepInEx.Unix
  6. {
  7. internal static class ConsoleWriter
  8. {
  9. private static ConstructorInfo cStreamWriterConstructor = AccessTools.Constructor(AccessTools.TypeByName("System.IO.CStreamWriter"), new []{ typeof(Stream), typeof(Encoding), typeof(bool) });
  10. public static TextWriter CreateConsoleStreamWriter(Stream stream, Encoding encoding, bool leaveOpen)
  11. {
  12. var writer = (StreamWriter)cStreamWriterConstructor.Invoke(new object[] { stream, encoding, leaveOpen, });
  13. writer.AutoFlush = true;
  14. return writer;
  15. }
  16. }
  17. }