protected override void ProcessRecord() { if (InputObject == null || InputObject.Length == 0) { return; } foreach (var obj in InputObject) { if (notFirst) { if (Stream) { WriteObject(""); } else { _lines.Add(""); } } notFirst = true; foreach (var line in FormatEngine.Format(obj)) { if (Stream) { WriteObject(line); } else { _lines.Add(line); } } } }
public void TestMethod1() { var result = FormatEngine.Format(typeof(string)).ToArray(); Assert.AreEqual(1, result.Length); Assert.AreEqual(typeof(string).ToString(), result[0]); }
public void TestListFormat() { var currentProcess = Process.GetCurrentProcess(); dynamic p = new PSObject(currentProcess); var properties = new [] { "ProcessName", "MachineName", "Company" }; var l = new ListFormat(ListEntries(properties)); IEnumerable <string> r = FormatEngine.Format(p, l); var result = r.ToArray(); Assert.AreEqual(3, result.Length); var fmt = "{0,-" + properties.Max(prop => prop.Length) + "} : {1}"; Assert.AreEqual(string.Format(fmt, "ProcessName", currentProcess.ProcessName), result[0]); Assert.AreEqual(string.Format(fmt, "MachineName", currentProcess.MachineName), result[1]); Assert.AreEqual(string.Format(fmt, "Company", p.Company), result[2]); }
protected override void ProcessRecord() { if (InputObject == null || InputObject.Length == 0) { return; } bool first = true; _objects.AddRange(InputObject); foreach (var obj in InputObject) { foreach (var line in FormatEngine.Format(obj)) { if (!first) { Console.WriteLine(); } first = false; Console.WriteLine(line); } } }