36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
namespace MeetTheTeacher.Export;
|
|
|
|
/// <summary>
|
|
/// Base class for exporters which write data to a file
|
|
/// </summary>
|
|
public abstract class FileExporterBase
|
|
{
|
|
/// <summary>
|
|
/// File extension of the exported file including the dot
|
|
/// </summary>
|
|
protected abstract string FileExtension { get; }
|
|
|
|
/// <summary>
|
|
/// Exports the given content to a file with the given name.
|
|
/// If the file already exists, it will be overwritten.
|
|
/// </summary>
|
|
/// <param name="fileName">Name of the file to export without the extension</param>
|
|
/// <param name="content">Content to write into the file</param>
|
|
protected void Export(string fileName, string content)
|
|
{
|
|
string filePath = GetFilePath(fileName);
|
|
File.WriteAllText(filePath, content);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Joins several lines into one text, separated by line breaks
|
|
/// </summary>
|
|
/// <param name="lines">Lines to merge</param>
|
|
/// <returns>A text containing all lines</returns>
|
|
protected static string LinesToText(IEnumerable<string> lines) => string.Join(Environment.NewLine, lines);
|
|
|
|
private string GetFilePath(string fileName)
|
|
{
|
|
return Path.Combine(Directory.GetCurrentDirectory(), $"{fileName}{FileExtension}");
|
|
}
|
|
}
|