Exemple #1
0
        private static void LogWithColor(string color, string text, WriteBehaviour line = WriteBehaviour.Line)
        {
            Console.Write(color);
            Console.Write(text);
            Console.Write("\x1b[0m");

            if (line == WriteBehaviour.Line)
            {
                Console.WriteLine();
            }
        }
Exemple #2
0
        private static FileMode GetAndCheckWriteMode(WriteBehaviour givenWriteBehaviour, string filePath)
        {
            switch (givenWriteBehaviour)
            {
            case WriteBehaviour.Append:
                return(FileMode.Append);

            case WriteBehaviour.Overwrite:
                return(FileMode.Create);

            case WriteBehaviour.Throw:
                if (System.IO.File.Exists(filePath))
                {
                    throw new IOException($"File already exists: {filePath}");
                }
                return(FileMode.Create);

            default:
                throw new ArgumentException("Unsupported write option: " + givenWriteBehaviour);
            }
        }