📄 OutGridTree/ColumnFormatter.cs
using System;
using System.Management.Automation;

namespace OutGridTree;

internal abstract class ColumnFormatter
{
    private ColumnFormatter() { }

    public static ColumnFormatter FromDisplayEntry(DisplayEntry displayEntry) =>
        displayEntry.ValueType switch
        {
            DisplayEntryValueType.Property => new Property(displayEntry.Value),
            DisplayEntryValueType.ScriptBlock => new Script(ScriptBlock.Create(displayEntry.Value)),
            _ => throw new ArgumentException(
                $"Unrecognized {nameof(DisplayEntryValueType)}: {displayEntry.ValueType}.",
                nameof(displayEntry)
            ),
        };

    public sealed class Property(string name) : ColumnFormatter
    {
        public string Name { get; } = name;
    }

    public sealed class Script(ScriptBlock scriptBlock) : ColumnFormatter
    {
        public ScriptBlock ScriptBlock { get; } = scriptBlock;
    }
}