Files
2025-04-19 20:47:58 +03:00

38 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Beam.Exports {
public class PlainTextExporter : IExporter, IAsyncExporter {
public PlainTextExporter(IDocument document) {
Document = document;
}
public IDocument Document { get; }
protected virtual string Convert() {
return Document.ToString();
}
protected virtual Task<string> ConvertAsync() {
return Task.FromResult(Document.ToString());
}
public virtual void Write(string path) {
var text = Convert();
if (!Directory.Exists(Path.GetDirectoryName(path)))
throw new ArgumentException(S.M.FileDirectoryDoesNotExist, nameof(path));
File.WriteAllText(path, text, Encoding.Unicode);
}
public virtual async Task WriteAsync(string path) {
var text = await ConvertAsync();
if (!Directory.Exists(path))
throw new ArgumentException(S.M.FileDirectoryDoesNotExist, nameof(path));
await File.WriteAllTextAsync(path, text);
}
}
}