예제 #1
0
        public static void Echo(
            this IDataObject dataObject,
            EchoEvaluationContext ctx)
        {
            var(@out, context, opts) = ctx;
            if (context.EchoMap.MappedCall(dataObject, ctx))
            {
                return;
            }

            var options = opts as TableFormattingOptions;

            options ??= (TableFormattingOptions)
            context.ShellEnv.GetValue <TableFormattingOptions>(ShellEnvironmentVar.display_tableFormattingOptions)
            .InitFrom(opts);
            options = new TableFormattingOptions(options)
            {
                PadLastColumn = false
            };
            var attrs = dataObject.GetAttributes();

            attrs.Sort((x, y) => x.Name.CompareTo(y.Name));

            object container = null;

            if (dataObject is DataValue dataValue &&
                !(dataValue.Value is IDataObject))
            {
                container = dataValue.Value;
            }

            var dt = GetVarsDataTable(context, container, attrs, options);

            dt.Echo(new EchoEvaluationContext(@out, context, options));
        }