internal static string FormatSingleLineDirect(PSObject obj,
                                                      ScriptBlock script,
                                                      PsContext ctx)
        {
            string val;

            using (FormatAltSingleLineCommand cmd = new FormatAltSingleLineCommand())
            {
                val = cmd.RenderScriptValue(obj, script, false, ctx);
            }
            // TODO: What to do if it spans more than a line? Just truncate? Issue a
            // warning? Add "..."? Also, consider that the view definition might have been
            // generated.
            if (null == val)
            {
                return(String.Empty);
            }
            else
            {
                int idx = CaStringUtil.ApparentIndexOf(val, '\n');
                if (idx < 0)
                {
                    return(val);
                }
                else
                {
                    return(CaStringUtil.Truncate(val, idx));
                }
            }
        } // end FormatSingleLineDirect
Example #2
0
        }         // end RenderScriptValue()

        protected object FormatSingleLine(object obj)
        {
            return(FormatAltSingleLineCommand.FormatSingleLineDirect(obj));

            // The direct route seems a littl risky; I'll keep this code around for now.
            // var shell = _GetCleanShell().AddCommand( "Format-AltSingleLine" );
            // Collection< PSObject > results = shell.Invoke( new object[] { obj } );
            // Util.Assert( results.Count <= 1 );
            // if( results.Count > 0 )
            //     return results[ 0 ];
            // else
            //     return String.Empty; // or should I return null?
        } // end FormatSingleLine()