Viyi.Util.Build/Builder/Builder.cs

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

namespace Viyi.Util.Build.Builder;

internal interface IBuilder {
    void Build();
    Task BuildAsync();
}

internal abstract class Builder : IBuilder {
    protected TextWriter? Writer { get; set; }
    protected string FilePath { get; }

    protected Builder(string filePath) {
        FilePath = Path.IsPathRooted(filePath)
            ? filePath
            : Path.Combine(this.GetTargetRoot(), filePath);
    }

    public virtual Task BuildAsync() {
        return Task.Run(() => Build());
    }

    public virtual void Build() {
        using var writer = Writer = CreateWriter(FilePath);
        try {
            WriteHeader();
            WriteContent();
            WriteFooter();
        }
        finally {
            Writer = null;
        }
    }

    protected virtual TextWriter CreateWriter(string filePath) {
        return new StreamWriter(filePath);
    }

    protected virtual void Write(string text) {
        Writer?.Write(text);
    }

    protected virtual void WriteIndent(int n) {
        Writer?.Write(string.Concat(Enumerable.Repeat("    ", n)));
    }

    protected virtual void WriteLine(string line) {
        Writer?.WriteLine(line);
    }

    protected virtual void WriteLine() {
        Writer?.WriteLine();
    }

    protected virtual void WriteHeader() {
        WriteLine("// This file is generated by Viyi.Util.Build, please keep it as it is.");
    }

    protected virtual void WriteContent() { }

    protected virtual void WriteFooter() {
后面还有 19 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。